I have a form for logging into my website. I need to make it so that when the user hits enter, the form submits. How can I do this? Please provide code.
<form id="login" action="myHome.php" method="POST">
<input type="text" name="email" id="email"/>
<br/>
<br/>
<input type="text" name="password" id="password"/>
</form>
You need to add an <input type="submit"> and hide it with CSS so that the browser knows what to trigger when enter is pressed, yet still not show a button. For the sake of accessibility and ease of use, I'd show the button even if not that many people use it (enter is much nicer).
Create a button by dragging a macro to a form In the Navigation Pane, locate the macro that you want the new command button to run, and then drag the macro to the form.
Yes, structurally the submit button needs to be inside a form element for the document to be valid X/HTML. But visually you can position the submit button anywhere you want with appropriate CSS (float, absolute/relative positioning, etc).
Have you actually tried anything?
You need to add an <input type="submit">
and hide it with CSS so that the browser knows what to trigger when enter is pressed, yet still not show a button. For the sake of accessibility and ease of use, I'd show the button even if not that many people use it (enter is much nicer).
add a handler to on keydown and check for keycode == 13. Make this submit the form like below
function addInputSubmitEvent(form, input) {
input.onkeydown = function(e) {
e = e || window.event;
if (e.keyCode == 13) {
form.submit();
return false;
}
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With