php - one form, multiple submits with onclick event -


i have form 2 submit buttons, in code behind got values each submit, problem when add javascript onclick event on each submit, when try retrieve values in php nothing. input submit values when don't use event.

i don't input submit values code:

<input type="submit" id="send1" value="send1" name="sub1" onclick="validate1();"/> <input type="submit" id="send2" value="send2" name="sub2" onclick="return validate2();"/> 

this 1 works:

<input type="submit" id="send1" value="send1" name="sub1" /> <input type="submit" id="send2" value="send2" name="sub2" /> 

here's quick setup want https://jsfiddle.net/d090618g/

your html

 <form id="theform">      <input type="submit" name="s1" />      <input type="submit" name="s2" />      <input type="hidden" name="clicked" id="clicked" />  </form>      <div id="result"></div> 

quick jquery

var $form    = $("#theform"); var $clicked = $("#clicked");  $form.find( "input[type='submit']").click( function(){     $clicked.val( $(this).attr('name') ); });  $form.submit( function( e ){     e.preventdefault();      switch( $clicked.val() ){          case 's1':             alert( "do thing 1" );             return;          case 's2':             alert( "do thing 2" );             return;     }      //post form php here              $("#result").html( $clicked.val() );  }); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -