0

I have HTML form with three Submit Buttons. One is for reloading the page, the other one makes a database entry and the last one is a simple login button. Each button is also in a div.

When i try to login, i normally enter my username & password and then press enter (Im not tabbing out of the textbox). But instead of pressing the button "login", it presses the button "reload".

I found some ways with Javascript, JQuery and AJAX, but im not allowed to use any of these. All i use is PHP, CSS and HTML.

Is there a way to choose which Button i want to press when i use enter?

edit:

This is the form with the three submit buttons:

<form method="post"action="Sub.php">
<input type="text" id="txt" name="txt" value="text">
<input type="submit" id="refresh" name="refresh" value="Refresh">
<input type="submit" id="update" name="update" value="Update">
<input type="submit" id="login" name="login" value="Login">
<input type="text" id="txt" name="txt" value="text"></form>

This is the file, where i post it.

<?php
if(isset($_POST['login']))
{echo "Login has been pressed";}
if(isset($_POST['update']))
{echo "Update has been pressed";}
if(isset($_POST['refresh']))
{echo "Refresh has been pressed";} ?>

If i tab through the first file and press enter in one of the textboxes, i will allways press the submit button with the value "refresh".

  • 3
    Could you please show us what you've done so far? – António Ribeiro Feb 22 '16 at 08:23
  • What do you mean with "I am not allowed to use these" ? – Bart Friederichs Feb 22 '16 at 08:23
  • 1
    This is not a duplicate. This is a different question, she is asking about submitting it, not processing it. – Bart Friederichs Feb 22 '16 at 08:43
  • Since JS is considered as "dangerous", it is disabled on computers. – Gluray Simons Feb 22 '16 at 09:00
  • The default button is simply the first. Have a read here https://html.spec.whatwg.org/multipage/forms.html#implicit-submission I would have added this as the answer if @jeroen had not mistakenly closed this as a duplicate (it most certainly is not) – rjdown Feb 22 '16 at 12:29
  • @rjdown It was with the information available at the time :-) – jeroen Feb 22 '16 at 12:33
  • By the way, if you only need 1 button to submit the form, you should see if you can put the other buttons outside of the form. That would solve your problem although I don't really see where your login fields are in the code you posted. – jeroen Feb 22 '16 at 12:37

2 Answers2

-1

Convert your Submit type button to simple button type

$("#textbox_password_id").keyup(function(event){
  if(event.keyCode == 13) {
    $("#form_submit").submit();
  }
});

Other way you can place your Login button first, so whenever you will press it will take first submit click

Shri Suresh
  • 463
  • 1
  • 5
  • 20
  • _"I found some ways with Javascript, JQuery and AJAX, but im not allowed to use any of these. All i use is PHP, CSS and HTML."_ That means your answer doesn't cover what OP is asking. – Epodax Feb 22 '16 at 08:29
  • I also added "Other way you can place your Login button first, so whenever you will press it will take first submit click" – Shri Suresh Feb 22 '16 at 09:05
-1

Duplicate of How do I use two submit buttons, and differentiate between which one was used to submit the form?

Give each input a name attribute. Only the clicked input's name attribute will be sent to the server.

<input type="submit" name="reload" value="Reload"/>
<input type="submit" name="database" value="Database Entry"/>
<input type="submit" name="login" value="Login"/>

<?php
    if (isset($_POST['reload'])) {
        // Reload-button was clicked
    }
    elseif (isset($_POST['database'])) {
        // Database-button was clicked
    }
    elseif (isset($_POST['login'])) {
        // Login-button was clicked
    }
    else {
        // Failure
    }
?>
Community
  • 1
  • 1
itsphilz
  • 455
  • 2
  • 9
  • I allready got that. But this just looks, which button has been pressed. I want to change which button will be pressed. – Gluray Simons Feb 22 '16 at 09:08
  • There is no way for the browser to know what submit button you want it to submit when you press the enter key though. – itsphilz Feb 22 '16 at 09:09
  • I thought there might be a way if im giving each one of these buttons his own div-box. But if there really is no way of solving this problem without using JS, JQuery or AJAX, im just gonna leave it like that. Thanks!! – Gluray Simons Feb 22 '16 at 09:15