How to trigger a function when i press enter in a text box

Discussion in 'JavaScript' started by sahilcoolsmart, Aug 16, 2007.

  1. #1
    I am doing some AJAX project. And in that i have a form which gets submitted through AJAX. But what i want is when users press enter the submitting function should be called.
    Users have to press submit button as of now, and i don't want that.
     
    sahilcoolsmart, Aug 16, 2007 IP
  2. bibel

    bibel Active Member

    Messages:
    289
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    When you press enter in a text box, the form is submited.
    You just need to add onsubmit="return yourAjaxFunction()" to the form element.
    Just make sure yourAjaxFunction returns false.
     
    bibel, Aug 16, 2007 IP