When Radio Buttons have the focus, ENTER submits form

  • Profile Image
    simmonscomputer
    Asked on August 28, 2013 at 06:59 PM

    I have the ENTER key disabled using javascript that I got from this forum.  This works just fine for all fields on my form except radio buttons.  If a user presses enter when any of my radio buttons have the focus, the form is submitted.  If they press enter on any of the other fields, the form is not submitted.   I need ENTER to be disabled when radio buttons have the focus.  What am I doing wrong?  Here is link to my form:

    http://ctextiles.com/onlineapp.htm

     

    If you look at the source, you can see that the javascript I am using to disable the ENTER key is:

    <script language=javascript type=text/javascript>

    <!-- Script courtesy of http://www.web-source.net - Your Guide to Professional Web Site Design and Development 

    function stopRKey(evt) {

       var evt = (evt) ? evt : ((event) ? event : null);

       var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

       if ((evt.keyCode == 13) && (node.type=="text")) {return false;}

    }

    document.onkeypress = stopRKey; 

    -->

    </script>

     

    What am I missing?

  • Profile Image
    Goldo
    Answered on August 28, 2013 at 07:59 PM

    You will need to add onKeyPress="return stopRKey(evt) to all input type="checkbox" and to all input type="radio" .

    So from from example below.

    <input type="radio" class="form-radio" id="input_15_0" name="q15_areThere15" value="Yes" />

    it should be like below.. just add

    <input type="radio" class="form-radio" id="input_15_0" name="q15_areThere15" value="Yes" onKeyPress="return stopRKey(evt)"/>


    That should do it.

  • Profile Image
    Welvin
    Answered on August 28, 2013 at 07:59 PM

    Hi,

    Good day! You will need to add Radio and Checkbox Properties to the Javascript Codes for Stopper. Use the codes from this bin: http://pastebin.com/YLazbvaQ

     

    Thanks

  • Profile Image
    Goldo
    Answered on August 28, 2013 at 08:03 PM

    Welvin's code should obtain the same result. Use it instead. :)

  • Profile Image
    simmonscomputer
    Answered on August 28, 2013 at 08:22 PM

    Thanks, that works great. You guys are awesome!

  • Profile Image
    happysmart
    Answered on April 02, 2015 at 03:59 AM

    I have multiple pages form and it used to submit last Thank You page (which is page17) when i used to hit Enter button on the very first page even having required fields.

    So inserted this code and it solved the problem!

     

    <script language=javascript type=text/javascript>

    <!-- Script courtesy of http://www.web-source.net - Your Guide to Professional Web Site Design and Development 

    function stopRKey(evt) {

       var evt = (evt) ? evt : ((event) ? event : null);

       var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

       if ((evt.keyCode == 13) && (node.type=="text")) {return false;}

    }

    document.onkeypress = stopRKey; 

    -->

    </script>

  • Profile Image
    KadeJM
    Answered on April 02, 2015 at 10:23 AM

    @ happysmart 

    I've moved your thread here even though it is a related response about this topic which helped you.