ENTER key clearing form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric D. Braden

    ENTER key clearing form

    I feel like a fool for asking this; seems like I would have had more
    luck with Google, but alas...

    This is a little baby bit of code that a friend cooked up over a year
    ago. My problem is simply that hitting enter doesn't really submit
    the input. It just reloads with a cleared form. My desired effect is
    for hitting the Enter key to have the same effect as clicking the
    Submit button.

    Here's the code:

    <!-- saved from url=(0013)about :internet -->
    <script language = "javascript ">

    function opensite()
    {
    location = "http://www.state.ar.us/dfa/personnel_mgmt/
    classcodes/"+entry.num1.va lue+".txt";
    }

    </script>
    <center>
    <h2 align = "center">En ter the Class Code and click Submit</h2>



    <form id = "entry">
    <table>
    <tr>
    <td>
    <input type = "text" id = "num1"></input>
    </td>
    </tr>
    <tr>
    <td align = "right">
    <input type = "button" id = "submit" onclick = "opensite() " value =
    "Submit"></input>
    </td>
    </tr>
    </table>
    </form>
    </center>
    <h3 align = "center"><f ont color = "Navy">You will find the MQs at the
    bottom of the page.</font></h2>

    I tried to make heads or tails of this post
    :

    /thread/39d8b289a95afe7 9/10c205b5f6d17a0 f?lnk=st&q=
    javascript+ente r+key#10c205b5f 6d17a0f

    but I couldn't get it working.

    (and, yes, I know GoogleGroups is the devil, but I can't get a real
    newsreader at work)
  • Randy Webb

    #2
    Re: ENTER key clearing form

    Eric D. Braden said the following on 12/17/2007 10:28 AM:
    I feel like a fool for asking this; seems like I would have had more
    luck with Google, but alas...
    >
    This is a little baby bit of code that a friend cooked up over a year
    ago. My problem is simply that hitting enter doesn't really submit
    the input. It just reloads with a cleared form. My desired effect is
    for hitting the Enter key to have the same effect as clicking the
    Submit button.
    <URL:
    http://groups.google.c om/group/comp.lang.javas cript/browse_thread/thread/a0407c1a089957f 7/5e55858025df711 5?lnk=gst&q=det ect+enter+key#5 e55858025df7115 >

    <form onsubmit="opens ite();return false">

    And then change your button to a submit button.
    <input type = "button" id = "submit" onclick = "opensite() " value =
    "Submit"></input>
    <input type="submit" value="Submit">

    Then, when the form gets submitted it will execute the opensite()
    function and cancel submission of the form.
    (and, yes, I know GoogleGroups is the devil, but I can't get a real
    newsreader at work)
    Google Groups isn't the devil. People using Google Groups without
    realizing what it's going to screw up is the devil.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    Comment

    • Eric D. Braden

      #3
      Re: ENTER key clearing form

      On Dec 17, 12:02 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
      Eric D. Braden said the following on 12/17/2007 10:28 AM:
      >
      I feel like a fool for asking this; seems like I would have had more
      luck with Google, but alas...
      >
      snip helpful stuff
      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ -http://jibbering.com/faq/index.html
      Javascript Best Practices -http://www.JavascriptT oolbox.com/bestpractices/
      Thanks so much for your help! I had to hit myself on the head a few
      times to get the <form onsubmitbit to work, but everything's daisies
      now.

      Comment

      • RobG

        #4
        Re: ENTER key clearing form

        On Dec 18, 1:28 am, "Eric D. Braden" <bradener...@ho tmail.comwrote:
        I feel like a fool for asking this; seems like I would have had more
        luck with Google, but alas...
        >
        This is a little baby bit of code that a friend cooked up over a year
        ago. My problem is simply that hitting enter doesn't really submit
        the input. It just reloads with a cleared form. My desired effect is
        for hitting the Enter key to have the same effect as clicking the
        Submit button.
        Irrelivant to your issue, which Randy has answered, but anyhow...
        >
        Here's the code:
        >
        <!-- saved from url=(0013)about :internet -->
        <script language = "javascript ">
        The language attribute is deprecated, type is required:

        <script type="text/javascript">

        <URL: http://www.w3.org/TR/html4/interact/...#adef-language >

        [...]
        <center>
        The center element is deprecated, use CSS styling instead.

        <URL: http://www.w3.org/TR/html4/present/g...ml#edef-CENTER >

        [...]
        <input type = "button" id = "submit" onclick = "opensite() " value =
        "Submit"></input>
        Closing tags for input elemens are forbidden.

        <URL: http://www.w3.org/TR/html4/interact/...tml#edef-INPUT >


        There are other issues with your markup, use a validator. The W3C
        HTML validator is pretty good:

        <URL: http://validator.w3.org/ >

        --
        Rob

        Comment

        Working...