How to disable form submit when hitting enter?

Discussion in 'JavaScript' started by Devtard, Sep 27, 2012.

  1. #1
    I have 2 inputs and I need to prevent hitting enter from submitting the form. I do not know the name/id of the form. Any ideas how to achieve this?
     
    Solved! View solution.
    Devtard, Sep 27, 2012 IP
  2. Sitesupplier

    Sitesupplier Peon

    Messages:
    16
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    0
    #3
    You know, I'm pretty sure this default behaviour is made redundant by simply including some hidden form elements after the last usable element, but before the submit button. You could always not include a "Submit" button, instead using a regular button with a "click" event listener attached to it where a function may be called to submit the form manually.

    Just a note: it may be the case that hidden form elements don't come with this behaviour, but regular elements do. If this is indeed the case, you could just add some regular elements in before the end of the form (1 is enough) and use CSS to disable their display.
     
    Sitesupplier, Sep 28, 2012 IP
  3. Devtard

    Devtard Notable Member

    Messages:
    850
    Likes Received:
    133
    Best Answers:
    4
    Trophy Points:
    220
    #4
    Thanks, plussy.
     
    Devtard, Oct 1, 2012 IP