javascript - Check to see if a button is clicked on... not working -


just brief explanation of part of code does:

  • i have 2 buttons different things.
  • one of them lets user search through table/database whatever he/she wants search for
  • the other lets user insert things database

what i'm trying do: i'm trying check see button user clicked on appropriate code executed.

i've been looking around , pretty everywhere go, people suggesting use isset(), it's not working me. perhaps don't understand isset() does, doesn't check see whether variable set?

here's code:

<script>      function show(x, y){                  <!-- -->              }  </script>      <form>      <button name = "sbutton" type = "button" onclick = 'show("searchform", "insertform");'>perform search</button>      <button name = "ibutton" type = "button" onclick = 'show("insertform", "searchform");'>insert data</button>  </form>      <form id = "searchform" value "search" style = "display: none;" action = "test2.php" method = "post">        <!-- -->      </form>    <form id = "insertform" style = "display: none;" action = "test2.php" method = "post">        <!-- -->      </form>

<!-- test2.php page -->    if(isset($_post['sbutton'])){  			      <!-- -->    }  else{  			      <!-- -->    }

to test it, had if statement print "checked" , else print "not checked". when run code, prints "not checked". doing wrong , should doing?

thanks in advance!

you not passing buttons sbutton or ibutton test2.php because second , third form not have them input. inputs inside each particular form submitted. , form has buttons has no action buttons call js function.

what suggest add hidden fields each form submitting test2.php follows:

<form id = "searchform" value "search" style = "display: none;" action = "test2.php" method = "post">      <input  type="hidden" name = "sbutton" value="sbutton" />     <!-- -->  </form>  <form id = "insertform" style = "display: none;" action = "test2.php" method = "post">     <input  type="hidden" name = "ibutton" value="ibutton" />     <!-- -->  </form> 

this way test2.php should work.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -