SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    submit form with enter

    I have a form and I post the values with javascript and ajax (prototype).
    I want when user press enter to submit this form, this is not doing now,how can I do that?
    It is a form with a "on submit=return action()" .
    Dimis

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    When you have a form element with type of submit, the enter key from any element within that form will submit that form.

    Code javascript:
    <form id="someForm" action="processform.php">
        <p><input type="text" name="someName"></p>
        <p><input type="submit" name="submit" class="submit" value="Submit"></p>
    </form>

    If you don't want the submit button to be visible, you can use css to hide the submit button and the enter key will still submit the form for you.

    Code css:
    .submit {
        display: none;
    }

    While it is possible to achieve similar results using javascript, it's not as effective and is more prone to failing under different circumstances.
    Using the submit button is the most effective way to achieve what you're after.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •