By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,447 Members | 985 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,447 IT Pros & Developers. It's quick & easy.

Form Button Confirmation

P: 18
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.
Jun 26 '08 #1
Share this Question
Share on Google+
3 Replies


gits
Expert Mod 5K+
P: 5,390
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
Jun 26 '08 #2

P: 18
Thanks. I appreciate the help. I'm going to try this:

onSubmit="return validateForm(this)"


Expand|Select|Wrap|Line Numbers
  1. function validateForm(frmObj) {
  2.  
  3. // do form validation here using frmObj
  4. // any validation failures, show alert and return false
  5.  
  6. // if form has been validated, confirm submission using:
  7. var answer = confirm("Ready to submit?")
  8.  if (answer) {
  9.    return true;
  10.  }
  11.  else {
  12.    return false;
  13.  }
  14. }
Jun 26 '08 #3

gits
Expert Mod 5K+
P: 5,390
this should work ;) ... just a note to minify the lines of code:

Expand|Select|Wrap|Line Numbers
  1. function validateForm(frmObj) {
  2.     // do form validation here using frmObj
  3.     // any validation failures, show alert and return false
  4.  
  5.     // if form has been validated, confirm submission using
  6.     return (confirm('Ready to submit?'));
  7. }
  8.  
kind regards
Jun 27 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.