473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Call function only once on enter key press

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
2 4183
hsriat
1,654 Expert 1GB
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
1,654 Expert 1GB
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

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

Similar topics

5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
4
by: Giloosh | last post by:
Hello Everyone, Is there a way to hit "ENTER"(or any other key) on the keyboard and trigger a sepcific button? I heard something about the onKeyDown event but was very confused with it. Could...
5
by: junk mail | last post by:
My friend is trying to code a small c program where he wants to force the user to press enter and only enter to continue. Currently he is using getchar() with a loop but you can type any number...
5
by: Tom Lam lemontea | last post by:
Hi all, This is my very first post here, I've seriously tried some programming on C, and shown below is my very first program(So you can expect it to be very messy) that I wrote after I've learned...
3
by: Hsg | last post by:
Hi all.. in C# , and specally in Forms ... i had creat a form , the user enter Inputs , and then press the Button ... is there a way that the user will have teh choice to press the Button on...
5
by: Stan Sainte-Rose | last post by:
Hi, How can I call an event from an action. Example, I want to call the datagrid.Double.click event when a button is pressed. Stan.
2
by: srini4vasan | last post by:
#include <stdio.h> int main() { char n, m; puts (" Enter the first string and . to terminate :"); do { n = getchar(); putchar(n);
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.