Call function only once on enter key press

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepikashalini
    New Member
    • Mar 2008
    • 18

    #1

    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(e vent.keyCode==1 3) return validate(this.f orm);" >[/HTML]

    i call the function in this line the function will be executed in number of times
    Last edited by gits; May 27 '08, 03:51 PM. Reason: added code tags
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Modify it like this...
    [html]<input type="password" name="password" class="inputbox " size="19" alt="password" onkeydown="if(e vent.keyCode==1 3) return validate(this);" >[/html]

    And in the function validate(arg), insert 2 lines in the starting as:
    [code=javascript]arg.blur();
    arg.disabled = true;[/code]
    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.

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      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.

      Comment

      Working...