PDA

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


Cali
10-07-2006, 09:41 PM
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...

_Aerospace_Eng_
10-07-2006, 10:39 PM
<!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>

Cali
10-14-2006, 11:22 PM
Thank you, works great!

Cali