fabmxer
12-17-2008, 10:18 PM
EDIT:
------------RESOLVED------------
Hey, I'm learning javascript and was wondering how to perform this rather simple script. I just want a prompt box to ask for a user name(or just text) when the page loads, then when I enter some text and click ok, that text will be displayed on the current page, ( preferrably a div )
It seems so simple yet it won't work, here's my attempted code.
<html>
<head>
<title> Script </title>
<script type="text/javascript">
function displayUserName() {
var message = "";
var userName = prompt("Enter the name");
if (userName) {
message = userName;
}
document.getElementById("usernamediv").innterHTML = message;
}
</script>
</head>
<body onload="displayUserName();">
<div id="usernamediv">
</div>
</body>
</html>
------------RESOLVED------------
Hey, I'm learning javascript and was wondering how to perform this rather simple script. I just want a prompt box to ask for a user name(or just text) when the page loads, then when I enter some text and click ok, that text will be displayed on the current page, ( preferrably a div )
It seems so simple yet it won't work, here's my attempted code.
<html>
<head>
<title> Script </title>
<script type="text/javascript">
function displayUserName() {
var message = "";
var userName = prompt("Enter the name");
if (userName) {
message = userName;
}
document.getElementById("usernamediv").innterHTML = message;
}
</script>
</head>
<body onload="displayUserName();">
<div id="usernamediv">
</div>
</body>
</html>