PDA

View Full Version : [Help] How to display text from alert prompt box?


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>

rangana
12-17-2008, 11:14 PM
You have some typo here:

document.getElementById("usernamediv").innterHTML = message;

fabmxer
12-17-2008, 11:26 PM
Thanks for the response....

But the entered text still doesn't appear on the screen, the way I coded it, does it make sense?

rangana
12-17-2008, 11:27 PM
Verify at your end that you have JS enabled. All things works fine for me.

fabmxer
12-17-2008, 11:39 PM
I do have JS enabled. The window pops up and I enter text into the box, but when I press ok, the text I just entered doesn't appear on the page. That's what I'm trying to achieve.

rangana
12-18-2008, 12:41 AM
Please provide a link to your page.

As I said, everything is working fine at my end.

fabmxer
12-18-2008, 01:35 AM
Hey I don't know why, the file wasn't saving I guess and the innterHTML saves never took place....

Thanks a bunch man.....

rangana
12-18-2008, 01:37 AM
Still works fine from the link you've given.

I have this strange feeling that your browser caches the old file.

Try to give it a hard-refresh (CTRL + F5)