Briek Posted March 8, 2007 Share Posted March 8, 2007 hello, I have this code : <INPUT TYPE="Submit" VALUE="Change Password" name="ChangePasswd" TABINDEX=4> <INPUT TYPE="Submit" VALUE="Login" name="action" TABINDEX=3> Problem : When the enter is pressed, the first submit is executed. -> "Change Password". I want that when enter is pressed that the "Login" button is triggered. Is there a possibility to set the enter to "Login" without changing the the place of the buttons??? (if I put "Login" button before "Change Password"; Enter does the "Login", but this is no option) Thx in advance Link to comment https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/ Share on other sites More sharing options...
Glyde Posted March 8, 2007 Share Posted March 8, 2007 Not that I can think of. By default, I believe browsers search for the first button. You can try: <INPUT TYPE="button" VALUE="Change Password" name="ChangePasswd" TABINDEX=4 onclick="this.form.submit()"> <INPUT TYPE="submit" VALUE="Login" name="action" TABINDEX=3> Not sure how that'll work Link to comment https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/#findComment-202630 Share on other sites More sharing options...
Psycho Posted March 8, 2007 Share Posted March 8, 2007 Well, this really isn't a PHP question and belongs in either HTML or Javadcript forum. But to answer your question, here's one solution: Without seeing the layout of the page I would say that you need to use javascript. Just create a hidden field for the submit type and then use javascript on the submit buttons to populate the field instead of sending the value as the submit value: <input type="hidden" name="submitValue" id="submitValue"> <INPUT TYPE="Submit" VALUE="Change Password" name="ChangePasswd" TABINDEX=4 onclick="document.getElementById('submitValue').value=this.value;"> <INPUT TYPE="Submit" VALUE="Login" name="action" TABINDEX=3 onclick="document.getElementById('submitValue').value=this.value;"> Link to comment https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/#findComment-202631 Share on other sites More sharing options...
Briek Posted March 8, 2007 Author Share Posted March 8, 2007 With onclick="this.form.submit()" : the "Login" is done when enter is pressed. But the "Change Password" doesn't work anymore. Here more of my code: <HTML><HEAD></HEAD> <body bgcolor="#FFFFEE" link="#FF8C00" vlink="#FF8C00" alink="#FF8C00" OnLoad="document.index.USER.focus();"> <FORM name="index" method="POST"> <INPUT TYPE="text" NAME="USER" TABINDEX=1> <INPUT TYPE="password" NAME="PASSWORD" TABINDEX=2> <INPUT TYPE="Button" VALUE="Change Password" name="ChangePasswd" TABINDEX=4 onclick="this.form.submit()"> <INPUT TYPE="Submit" VALUE="Login" name="action" TABINDEX=3> </FORM> <?php $action = $_POST['action']; $ChangePasswd = $_POST['ChangePasswd']; if ($action == "Login" or $ChangePasswd == "Change Password") { } ?></BODY></HTML></html> Problem : with onclick="this.form.submit()" -> the $_POST['ChangePasswd'] isn't triggered Can somebody solve this??? thanks in advance Link to comment https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/#findComment-202639 Share on other sites More sharing options...
Psycho Posted March 8, 2007 Share Posted March 8, 2007 <HTML><HEAD></HEAD> <body bgcolor="#FFFFEE" link="#FF8C00" vlink="#FF8C00" alink="#FF8C00" OnLoad="document.index.USER.focus();"> <FORM name="index" method="POST"> <INPUT TYPE="text" NAME="USER" TABINDEX=1> <INPUT TYPE="password" NAME="PASSWORD" TABINDEX=2> <INPUT TYPE="button" VALUE="Change Password" name="ChangePasswd" TABINDEX=4 onclick="this.form.submit()"> <INPUT TYPE="Submit" VALUE="Login" name="action" TABINDEX=3> </FORM> <?php if (isset($_POST)) { //User submitted the page if (isset($_POST['action'])) { echo "User clicked Login"; } else { echo "User clicked Change password"; } } ?></BODY></HTML></html> Link to comment https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/#findComment-202648 Share on other sites More sharing options...
Briek Posted March 9, 2007 Author Share Posted March 9, 2007 if (isset($_POST)) { //User submitted the page if (isset($_POST['action'])) { echo "User clicked Login"; } else { echo "User clicked Change password"; } } The "if (isset($_POST))" is always true so the "else {echo "User clicked Change password";}" is always triggered. Somebody can fix this???? Thx Link to comment https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/#findComment-203269 Share on other sites More sharing options...
Psycho Posted March 9, 2007 Share Posted March 9, 2007 if (isset($_POST['USER'])) { //User submitted the page if (isset($_POST['action'])) { echo "User clicked Login"; } else { echo "User clicked Change password"; } } Link to comment https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/#findComment-203277 Share on other sites More sharing options...
rameshfaj Posted March 9, 2007 Share Posted March 9, 2007 try this: $mode=$_GET["mode"];//if method=get if($mode=="submitbutton1") {} elseif($mode=="submitbutton2") {} else {} www.jobspokhara.com.np Link to comment https://forums.phpfreaks.com/topic/41783-2-submit-buttons-on-1-page/#findComment-203285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.