similar to how we have onfocus and onclick on input tags I am using the below method( if the method is wrong please let me know what would be the proper method ) for submitting a form when someone presses enter on a textbox in a field in a form
Example when someone writes the password in the password field and presses enter (when the cursor is on the password field) the form should submit.
I even have a submit button but I want the same thing to happen when text has enter pressed when submit is clicked
I am using this right now
onkeypress='if (event.keyCode == 13) { validate(); }'
for my textbox fields
the issue over here is that when the history of my text box shows below my text box and I select it by pressing enter it does not take the value first in my text box. It straight away validates the value in the text box
Example: I have typed abcin my email textbox, I get abc@xyz.com below my text box showing that I had typed that earlier, not when I do down by pressing the down arrow and pressing enter it does not take abc@xyz.com in my text box but straight away runs validate() anhd gives me an error as wrong email format.
I believe it should first take my old value in the text box and then run the validate function
I am using codeigniter
Not sure to have understood your question,
maybe you need a code like this:
function submitMe(event) {
if (window.event.keyCode == 13)
{
document.myForm.submit();
}
}
Then in your HTML:
<input type="input" ... onKeyPress="submitMe(event)" value="">
or you can use autocomplete="off"
instead of value=""
<input type="input" ... onKeyPress="submitMe(event)" autocomplete="off">
您是否尝试过方法:onsumbit:
<form method="post" onsubmit="validate()">...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.