On Mar 16, 8:36 am, Jack Jones <jack.jo...@zxcv231.co.ukwrote:
* Tom Cole wrote:
On Mar 16, 6:22 am, Jack Jones <jack.jo...@zxcv231.co.ukwrote:
Actually I get...... "undefined" when I click on the body and , I don't
get an alert box when the page loads. So there must be something else
wrong too. So many mistakes in code so short? eek
You won't get an alert box when the page loads because your alert call
is inside an event handler, onclick. So .... until you click, no
alert...
No its ALSO called in onload
<body onload="say('test')">
So how come THAT doesn't work?
probably because you're still not clicking on the body.
<html>
<head>
<script type="text/javascript">
function say(message) {
var text = message;
document.onclick = function () {alert(text);};
}
</script>
</head>
<body onload="say('test')">
This is a <i>test</idocument.
</body>
</html>
i put the gave the document the onclick event handler so you can click
wherever you please on the page now and get the alert message.
you have to *click* the page if you want to see the alert message. if
you want the alert to popup when the page loads do this:
<body onload="alert('test')">