Form Button Confirmation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Danigan
    New Member
    • Sep 2007
    • 18

    Form Button Confirmation

    Need: I have a form. When the user clicks "submit", I need a dialog box to say "Are you finished?" Then I need the Yes/OK button to submit and No/Cancel button to do nothing. Eventually I'll add more validation, but I can handle everything other than how submission would be controlled in a JavaScript environment.

    My guess: I'll probably have to add a button to the form that says "submit" (but no actual submit button anywhere). The onclick would call a function containing (pseudo code) if (confirm("text. ..) submit form xyz, else nothing

    Please let me know if I'm on the right track and how to submit the form via JavaScript. If instead I need to include a submit button, let me know how I would be able to "interrupt" it if the user clicked cancel. :-) Thanks.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    yes ... you are definitly on the right track ... use a button or the form's onsubmit-handler to call the code you have in mind already. in case you use the button you may use the submit() method, in case you want to use the onsubmit-handler just return true or false from there ...

    kind regards

    Comment

    • Danigan
      New Member
      • Sep 2007
      • 18

      #3
      Thanks. I appreciate the help. I'm going to try this:

      onSubmit="retur n validateForm(th is)"


      Code:
      function validateForm(frmObj) {
      
      // do form validation here using frmObj
      // any validation failures, show alert and return false
      
      // if form has been validated, confirm submission using:
      var answer = confirm("Ready to submit?")
       if (answer) {
         return true;
       }
       else {
         return false;
       }
      }

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        this should work ;) ... just a note to minify the lines of code:

        Code:
        function validateForm(frmObj) {
            // do form validation here using frmObj
            // any validation failures, show alert and return false
        
            // if form has been validated, confirm submission using
            return (confirm('Ready to submit?'));
        }
        kind regards

        Comment

        Working...