javascript - How can i use both onclick() function and POST method with form together? (php) -
i new php , need help. make practice decided work on project has similar points twitter .my problem when click submit button, button value didnt change. if put code out of form worked. need post control if value follow or followed. if followed code register id database. if turns follow delete id db.(i didnt write part yet , sorry, code little bit sketchy). there way solve problem? thank already.
<div id="bilgi"> <h3> <?php $name=$row["name"]; echo $name; ?> </h3> <h5>hey there! can follow me if want see tweets.</h5> <?php if ( $_post['butt']=="followed") { $sqlr = "insert follow(member_email,person_email) values ('$email','$term')"; $rqu = mysqli_query($conn,$sqlr); } ?> <div id="bbbb"> <form action="" method="post"> <input onclick="follow(this)" type="submit" value="follow" name="butt" /> </form> </div> </div> <script> function follow(element) { if ( element.value === "follow" ) element.value = "followed"; else element.value = "follow"; } </script>
you need separate function interacts database page button , access using ajax. ajax uses javascript send request script, example, "save contact database" script, don't leave page, way can click button again, toggle following/not following.
jquery makes ajax easy, expecially if you're binding events objects. should check out. jquery , ajax
Comments
Post a Comment