I've read a thousand threads about this topic, but they either don't apply to my exact problem, or I'm not smart enough to understand the answer. I'm OK at PHP, but I pretty much can only copy and past Javascript code. I think the solution is farily simple, I just don't know how to write the code. Here's my dilemma, simplified best I can:

The user is filling out a form with several fields. When they click 'Submit', a javascript looks at their selections and if certain criteria are met, a 'confirm' box pops up to ask them if they are sure they want to continue. If they click 'cancel', then nothing happens (so they can change their selections). If they click OK, then the contents of the form is sent to a new PHP page.

I need to know how to tell the next page that the 'confirm' box popped up, and (more importantly) that they clicked OK. Since the 'confirm' box on the previous page will only popup if certain requirements are met, it isn't a given that if the user gets to the next page that they saw the 'confirm' popup.

I'm thinking that a hidden form tag will work, but I haven't a clue where to put it or how to write it.

Here's a sample of the javascript for the 'confirm' popup box, which I just copied from somewhere and changed a little bit to work for my form:
function validate(theForm){

if (document.additional.method[0].checked && document.additional.finishdate.selectedIndex == 0)
{
ConfirmStatus = confirm("click OK if you're sure. or click cancel.")
if (ConfirmStatus == true) {return (true);}
if (ConfirmStatus == false) {return (false);}
}
}

So if they click OK, and the form passes the selections to the next page, I need to somehow tell my PHP code that they clicked OK.

Sorry to be such a rookie.
Thanks for the help.

    You don't have to be sorry for being a rookie.

    Yes, hidden forms work. Do you have the whole code, or the part where the user hits the confirm button?

    Also you'd be better advise to learn javascript and code your own thing, rather than copy+paste. It won't be as sofisitcated, but will be less complicated to modify. It would be better if you understood the code.

      Here's the submit button, if that helps:
      <input type=submit value='Continue' onClick=\"return validate(this)\">
      I'm not sure how much of the code you want to see. I'll attach the whole .txt file if you want. It's a real mess though...
      I'm slowly figuring out how javascript works. I understand all my js code, and I can change it to fit my needs, but I couldn't sit down and write something from scratch. Not yet anyway.
      Thanks!

        There's a pretty good JavaScript tutorial on Webmonkey. Try there and see if you like it.

          Originally posted by memongo23
          I need to know how to tell the next page that the 'confirm' box popped up, and (more importantly) that they clicked OK. Since the 'confirm' box on the previous page will only popup if certain requirements are met, it isn't a given that if the user gets to the next page that they saw the 'confirm' popup.

          function validate(theForm){

          if (document.additional.method[0].checked && document.additional.finishdate.selectedIndex == 0)
          {
          ConfirmStatus = confirm("click OK if you're sure. or click cancel.")
          if (ConfirmStatus == true) {return (true);}
          if (ConfirmStatus == false) {return (false);}
          }
          }

          Hi,
          But additional isn't the form name?

          In php page you can chek if $method[0] is checked and if $finishdate==0. If yes, the user click ok, else the popup was
          not displayed (beacuse if displayed and user click cancel, form
          isn't subitted and php not executed...).

          I hope this help...

            One thing,

            if your submit button is going to call a javascript function, instead of going to the page specified by the action attribute of the <form> tag, then the type should be "button" not "submit"

            Yes, your values must be on a hidden form element, between the <form> and </form> tags.

            <input type="hidden" name="variable_name" value="whats the value of that variable">

            you don't need to specify a name for the form, you don't need to when using PHP, but when using Javascript you do need it. So on the form which the javascript checks, use a name. One the form that is sent to the PHP script, don't use a name.

              I'm still really lost. I know how to pass a hidden form element, but I don't know how to combine it with javascript. I'm thinking I should have the hidden tag in the 'true' part of my confirm JS. Something like this:

              if (ConfirmStatus == true) {
              <input type=hidden name=confirm value=true>;
              return (true);
              }

              I've tried that, but that obviously didn't work.
              I tried to make a variable, but I dont' know how:

              if (ConfirmStatus == true) {
              var confirmOK = true;
              return (true);
              }

              No luck there either, of course. I just don't have any idea how to write JS.

              I'll try to attach a simplified .txt file of my code, if that's of any use. I'm not sure I know how though...
              Thanks for all the help.

                document.write("<input type=hidden name=confirm value=true>");

                  Suppose you have a form like this...

                  <FORM NAME="form1" ACTION="./my_script.php3" METHOD="POST">
                  <INPUT NAME="hidden_field" VALUE="" TYPE="HIDDEN">
                  </FORM>

                  If you want to change the value of "hidden_field" with JS, do something like this :

                  <SCRIPT LANGUAGE="JavaScript">
                  function Change_Value(new_Value) {
                  document.forms["form1"].hidden_field.value = new_Value;
                  }
                  var The_New_Value = true;
                  Change_Value(The_New_Value);
                  </SCRIPT>

                  It's very important to specify a name for the form and use THE SAME in JS. In this example, it is "form1".

                    thank you, thank you, thank you.

                    I can't even explain how wonderful these forums are, and how great it is that smart people are willing to help us beginners.

                    thanks!!

                      Write a Reply...