• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Jscript to stop enter submitting form"

Collapse

  • NickFitz
    replied
    Code:
    function checkIfTheFormIsReadyToBeSubmittedYetOrIfTheyMissedABit() {
        // check stuff here...
        if (everythingIsOk) {
            return true;
        }
        return false;
    }
    
    document.getElementById("theForm").onsubmit = checkIfTheFormIsReadyToBeSubmittedYetOrIfTheyMissedABit;
    // N.B. No brackets at the end of the line above is intentional - we want to assign the function, not the result of calling it :-)
    should do it - also stops them submitting it via the submit button, which you presumably also don't want if the form isn't complete

    Leave a comment:


  • mudskipper
    replied
    Ignore the above - doesn't work in IE10

    Leave a comment:


  • mudskipper
    replied
    Try something like:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    
    function disableEnter(e) {
      if(e.which==13 || e.keyCode==13) 
      {
        e.preventDefault();
      } 
    }
    
    </script>
    </head>
    <body>
    <form method="post" onkeypress="disableEnter(window.event)">
    <input type=text/>
    <input type="submit"/>
    </form>
    </body>
    </html>

    Leave a comment:


  • xoggoth
    started a topic Jscript to stop enter submitting form

    Jscript to stop enter submitting form

    Trying to write some online invoicing software and want to prevent submitting partially filled form with enter. Used the solutions on the net, ie
    stuck onkeydown='noenter();' on inputs and added some jscript:

    function noenter()
    {
    var x = event.which || event.keyCode;
    if (x == 13) return false;
    }

    Put same event code in the jscript on submit form validation and eventually got it to almost work by sticking onkeydown on ALL controls, even disabled ones, but if a control has been selected (even a disabled one!) and then enter is pressed it submits.

    Sounds trivial I know, but this is for a severely untechy person and it needs to be foolproof as possible. Any ideas why having a selected control causes the jscript to be ignored? Cheers.
    Last edited by xoggoth; 31 May 2016, 14:31.

Working...
X