By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Call function only once on enter key press

P: 18
In javascript i call a function at the time of to press an enter key. number of times i press a key the process will be activated. hoow to i ignore this problem

[HTML]<input type="password" name="password" class="inputbox" size="19" alt="password" onkeydown="if(event.keyCode==13) return validate(this.form);" >[/HTML]

i call the function in this line the function will be executed in number of times
May 27 '08 #1
Share this Question
Share on Google+
2 Replies


hsriat
Expert 100+
P: 1,654
Modify it like this...
[html]<input type="password" name="password" class="inputbox" size="19" alt="password" onkeydown="if(event.keyCode==13) return validate(this);" >[/html]

And in the function validate(arg), insert 2 lines in the starting as:
Expand|Select|Wrap|Line Numbers
  1. arg.blur();
  2. arg.disabled = true;
This will disable the password field, so no more event will be fired.

And use arg.form instead of the argument you were using earlier inside the validate function.

Also, when processing is done, you would need to enable the password field, if required.
May 27 '08 #2

hsriat
Expert 100+
P: 1,654
After all this, I'm just wondering, why did you need that to test for the enter key while, its already like that a form is usually submitted when you press enter in the password field. If you had to apply you validation, you could do that in form's onsubmit event.
May 28 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.