Javascript prompt then open new window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hcross
    New Member
    • May 2007
    • 3

    #1

    Javascript prompt then open new window

    This project is a web based html and Javascript site. I am working on mac at the moment. This script works except for attempting to open new window once complete.

    As you can see, i am new to javascript coding. Can i open a new browser window after my prompts and alerts have finished. I am not sure what i am doing wrong.


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitl ed Document</title>

    <script type="text/javascript">
    <!--
    function displayMessage( ) {
    alert("Hello " + ", thanks for being patient just a few more question before we procced!")

    var ans = prompt("Do you have some time to answer some questions?");
    if (ans == "no") {
    return;// stop the script
    }
    else {
    alert ("about to open window");
    window.open("fo rm2.html","test ","toolbar=no,m enubar=no,width =200,height=200 ,resizable=yes" ); // I want to a open new window after prompts are finished.

    alert ("Your answers will be placed in the appropriate areas, please check form once complete");

    alert ( "thank you, we shall proceed");
    prompt("Your first name");
    prompt("Your last name ");
    prompt("Your street address");
    prompt("Your apt number");
    prompt("Your city");
    }

    }

    </script>
    </head>

    <body onLoad ="javascript:di splayMessage(); ">
    i change this line every time i reopen the page to make sure i am opening the right page.

    </body>
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    First of all, this is not a good way to get input. Just let the user input the data themselves instead of using prompts.

    If you want to open the window after the prompts, you will have to move the window.open after the prompts.

    You will also want to save the inputs from the prompts, e.g.
    Code:
    var name = prompt("...

    Comment

    • hcross
      New Member
      • May 2007
      • 3

      #3
      this page is not supposed to collect the user information. My project is built to annoy the user, see how long a person keep on trying to enter information into a form that doesn't work.

      Thanks for the help, though.

      Comment

      • hcross
        New Member
        • May 2007
        • 3

        #4
        do you know how to redirect a form after validation has been completed. TO say thanks for taking the time to participate in our experiment.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by hcross
          this page is not supposed to collect the user information. My project is built to annoy the user, see how long a person keep on trying to enter information into a form that doesn't work.

          Thanks for the help, though.
          Hmm..an experiment. That would definitely be annoying.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by hcross
            do you know how to redirect a form after validation has been completed. TO say thanks for taking the time to participate in our experiment.
            By redirecting, do you mean to a new page? You can redirect using:
            Code:
            location.href=newurl

            Comment

            Working...