Web Analytics Made Easy -
StatCounter How do I place the result of a 'window.promt' in to a DIV tag? - CodingForum

Announcement

Collapse
No announcement yet.

How do I place the result of a 'window.promt' in to a DIV tag?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I place the result of a 'window.promt' in to a DIV tag?

    Hi,

    I'm trying to code a variable with a 'window.promt'. When the result is null, the window changes to page 2. When the 'window.promt' contains a value, I would like this value to be inserted into a DIV tag of page 1 (with 'window.document.getElementById("boucle").innerHTML' ? )

    Can anyone help me with writing a function that will make the 'window.promt' appear and the result go into the DIV tag? What I have so far is the variable and the promt. What I can't get is the DIV part. See below:

    var name;
    namePrompt = window.prompt("Please state your name");

    if ( (namePrompt == "") || (namePrompt == null) )
    {
    namePrompt = window.location.href = "page2.htm";
    }
    else
    {
    window.document.write("Hello " + namePrompt);
    }



    Thank you...

  • #2
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    var name;
    var namePrompt = window.prompt('Please state your name');
    window.onload = function()
    {
    name = (namePrompt == '' || namePrompt == null) ? window.location = 'page2.htm' : 'Hello ' + namePrompt;
    document.getElementById('namehold').firstChild.nodeValue = name;
    }
    </script>
    </head>
    
    <body>
    <div id="namehold">&nbsp;</div>
    </body>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      Thank you, works great!

      Cali

      Comment

      Working...
      X