/    Sign up×
Community /Pin to ProfileBookmark

Need help with simple code

JS never ceases to mystify me. Can some generous soul explain to me why this (simple) code doesn’t work:

<script type=”text/javascript” language=”javascript1.5″>
window.onload=message;

function message()
{
document.alert(“you are inside the message function”);

}

</script>
</head>

<body>

<script type=”text/javascript”>document.write(“hello world”); </script>

</body>
</html>

the file will produce “hello world” but why doesn’t also produce the alert message “you are inside the message function” ?

captsig
actual link is: [url]http://www.captsigerson.com/testjs.html[/url]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliDec 27.2011 — JS never ceases to mystify me.[/quote]
You can usually minimise that by using the error console. There's no such function as [I]document.alert[/I].
Copy linkTweet thisAlerts:
@xelawhoDec 27.2011 — you can demistify javascript a little by using a debugger like firebug.

then with your code you would get the message "document.alert is not a function"

so you would then maybe think of using:
[CODE]window.alert("you are inside the message function");[/CODE]
or even just:
[CODE]alert("you are inside the message function");[/CODE]
Copy linkTweet thisAlerts:
@cyberootDec 27.2011 — sample js code alert

[code=php]<html>
<head>
<script type="text/javascript">
function message()
{
window.alert("you are inside the message function");
}
</script>
</head>
<body onload="message()">
<script type="text/javascript">
document.write("hello world");
</script>
</body>
</html>[/code]
?
Copy linkTweet thisAlerts:
@captsigauthorDec 27.2011 — Doooh!

thanks very much
×

Success!

Help @captsig spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...