Jump to content
confused and dazed

How Do I Use A Yes/ No Confirm Pop Up Box After A Bunch Of Other Requirements Have Been Met

Recommended Posts

Hello internet.Here is my problem...I have a ton of "if...else if" statments in a javascript function. Once all those requirements have been met I would like to send the user a popup box to confirm if they want to submit the form. IT IS NOT WORKING FOR ME.I am trying to incorperate the following style of pop-up but it is not working. My function either skips right over this and sends the form to my PHP file for processing without this final check or nothing works at all. PLEASE HELP. function show_confirm(){var r=confirm("Press a button");if (r==true) { alert("You pressed OK!"); }else { alert("You pressed Cancel!"); }}

Share this post


Link to post
Share on other sites

I don't see how the code you're showing related to a PHP form. Where's the place that the function is called from?

Share this post


Link to post
Share on other sites

Please provide all the code you are using. The code you provided doesn't show us how you are using it within your form handling.

Share this post


Link to post
Share on other sites

I have a form called Tourney<form name=Tourney action="m m_post_process_4.php" method="post" onSubmit="return check()" target="_blank"> The php filem_m_post_process_4.php just simply echos all the button values back for the user to see the check() function has a bunch of if...else if statementshere is a bit of that code... else if (quadAA==1) { alert("You will need to fix Quad A") return false; }else if (quadBB==1) { alert("You will need to fix Quad B") return false;// etc..........and the else ifs go on and on and on... once the value is returned true I would like to send the user a final yes/no pop up box to submit the form to the PHP file.

Share this post


Link to post
Share on other sites

Instead of returning a value on each condition set a variable. At the very beginning of the check function create a variable and initialize it to true: var blnSubmit = true; Then at the bottom of all your if statements, you have something like this:

if (blnSubmit) {   var result = confirm("Are you sure?");   if (!result) {	  blnSubmit = false;   }}return blnSubmit

EDIT: You might also consider adding all your error messages to a single string to alert at the end of the function. It would be more user friendly. Instead of:alert("...");something like:errMsg += "..."; You'd have to initialize it to an empty string at the beginning of the function like you do with the blnSubmit variable.Then you could add an else clause to the if statement I provided above where you would alert the message.

Edited by ShadowMage

Share this post


Link to post
Share on other sites

That worked. AWSOME! thanks - one more question... when you said Instead of returning a value on each condition set a variable. At the very beginning of the check function create a variable and initialize it to true:I know you menat setting a variable for the final results but did you mean I could condense some of my code and not have to say return false; time after time after time...?

Share this post


Link to post
Share on other sites
Instead of returning a value on each condition set a variable. At the very beginning of the check function create a variable and initialize it to true:I know you menat setting a variable for the final results but did you mean I could condense some of my code and not have to say return false; time after time after time...?
My original suggestion does not really condense anything. Instead of writing return false; you'd be writing blnSubmit = false; instead.You could however, initialize the variable to false and add an else clause to your if structure which would set blnSubmit to true, thus eliminating the need to write blnSubmit = false; time and time again:
var blnSubmit = false;if (condition1) {   ...} else if (condition2) {   ...} else if (condition3) {   ...} else {   blnSubmit = true;}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...