Welcome Guest, Not a member yet? Register   Sign In
validate and submit form when enter is pressed in input(textbox) field
#1

[eluser]bleu[/eluser]
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 validating and submitting a form through javascript 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 validate and submit.

I even have a submit button but I want the same thing to happen when enter has been pressed on the textboxes

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 abc in my email textbox, I get abc@xyz.com below my text box showing that I had typed that earlier, now 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() and 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


The issue is that it should validate and submit form when enter is pressed in input(textbox) field, but currently it does not select history and run the javascript validation function


I am using codeigniter 2.1.0
#2

[eluser]PhilTem[/eluser]
Why don't you bind your validation on form submitting? That's much easier and helps you prevent these problems with people who use enter to select autofilled values. Even though you can have these values selected with pressing tab once it's highlighted Wink




Theme © iAndrew 2016 - Forum software by © MyBB