Hello.

I'm new to PHP, so this may be a simple question. I'm putting together a question and answer game page for a kids club that my daughter belongs to. The game page is in html and it works fine. What I want to do is, when the answer is entered and the submit button clicked, invoke a PHP page that will check the answer (so they can't just view the source to find out what it is - these kids are tricky). If the answer is correct, I want to display a "winners page". However, if it's wrong, I want to display a customized popup window (not an alert message) that says they were incorrect, with some sound effects and maybe some music.

The game page and winners page are both written in html. The problem is that I want the popup built and displayed out of the PHP page and displayed over the game page. Is that possible ... I suspect it is, I just don't know how. Can someone please help.

Thanks,
J.W.

    Popups are handled with Javascript.

      the popup page can be a php page, sounds like a modal window launched by javascript, but still a full web\php page in its own right.

        Dagon.

        I don't understand. Are you saying it can be done the way I want or it can't?

        J.W.

          jimweinberg;10907630 wrote:

          Dagon.

          I don't understand. Are you saying it can be done the way I want or it can't?

          J.W.

          Can

            If I understand correctly, what you want to do is send their response to a question to the server so that you can do some server-side checking on it. Then, if their response is correct, redirect them to a different page. Otherwise, you want them to stay on the same page but open a popup window that indicates they have chosen the incorrect answer?

            Sounds like you might need some AJAX to send their response to a PHP script. Then, that PHP script could send a response back as either "correct" or "incorrect". Your JS code could then handle the two appropriately (e.g. either window.location='newpage.html' or window.open('incorrect.html'), something like that).

            EDIT: Note that this would probably be the "better"/"Web 2.0" way to approach this. You could always just have a normal form that submits to a PHP script which can then either output the same page plus some JS that opens a popup window, OR use header() to redirect them to the next page.

              bradgrafelman.

              Yup, you got it. The idea of the two game pages (one with js and one without) was going to be my backup plan. However, since posting, I think I've come up with a solution. The codes below. The only problem I have now is that when the php page is invoked, it replaces the game page and when I close the wrong answer popup (with a button), I'm left looking at a blank page.

              If I could fix that problem, I'd be a very happy camper.

              Any ideas?

              code:

              <?php
              $answer = "Satsumi";
              if ($answer != $_POST[Guess]) {
              echo "
              <script>
              function popitup2() {
              newwindow2=window.open('','name','height=300,width=400,screenX=312,screenY=234');
              var tmp = newwindow2.document;
              tmp.write('<html><head><title>popup</title>');
              tmp.write('</head><body><p><center>');
              tmp.write('<font face=andy size=8>I&#39;m Sorry.<p>That&#39;s Incorrect.<p>Please try again.');
              tmp.write('<p><input type=button value=Try&nbsp;&nbsp;Again onclick=window.close()>');
              tmp.write('</body></html>');
              tmp.close();
              }
              </script>
              <body onload='javascript: popitup2()'>
              </body>
              </html>
              ";
              }
              else {
              echo "<script>window.location='winner.html'</script>";
              }
              ?>

                Write a Reply...