SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Form Problem

  1. #1
    SitePoint Member
    Join Date
    Sep 2005
    Location
    Hull, England
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Problem

    Whats up SitePointers?

    I'm having a real head scratching problem, on this new site I am making the client wants a form, they have asked me to use the form off the old site, but things aren't going well.

    When the use hits submit, the form works fine but if the user presses enter on the keyboard (which I always normaly do) the form does not work, this is because on the button it has this

    Code:
     onClick="submitentry()"
    anyway to sort this out so even if the user presses enter, the form still works?

    Thanks in advance!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    form submit

    Use an input type="submit"?

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    HTML Code:
    <form onsubmit="yourJavaScriptFunctionHere();">
    <input type="submit" value="Submit">
    </form>
    There you go.

  4. #4
    SitePoint Member
    Join Date
    Sep 2005
    Location
    Hull, England
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, but these don't seem to work.

    here is my form.

    Code:
    <form name="password1">
    <input type="password" name="password" size="10">
    <input type="button" value="Enter" onClick="submitentry()">
    </form>
    i tried this..

    Code:
    <form name="password1" onsubmit="submitentry()">
    <input type="password" name="password" size="10">
    <input type="button" value="Enter" >
    </form>
    but no luck..

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    form submit

    To have the form submit with an enter key event you have to use type="submit" not type="button", unless the button has focus (or test for an enter key event)

  6. #6
    SitePoint Member
    Join Date
    Sep 2005
    Location
    Hull, England
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <form name="password1" action="javascript:submitentry();">
    <input type="password" name="password2" size="10">
    <input type="button" name="submit" value="Enter" class="Button" onClick="submitentry()">
    fixed it, thanks!

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    Not Fixed

    If that last snippet "works" it is because the form had focus when you hit "enter". If you click outside of the form and hit "enter" it will NOT work. As mentioned many times already in this thread you need to use a TYPE SUBMIT, NOT a TYPE BUTTON (sorry to "yell" but you seem to be missing the answer)


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
  •