...

View Full Version : Simplest Alert Script Ever



toymachine22122
01-07-2004, 03:02 AM
This has got to be the simplest of all scripts, and yet it failed. This function is useless in webpages, really, I'm just trying to learn javascript from it. All I want it to do is alert "Silly rabbit, trix are for kids" except the word "Silly" is stored in a variable. Here's what I gots:



function UselessFunction() {
var Useless = 'Silly'
alert( Useless + "rabbit, trix are for kids!" )
}
</SCRIPT><BODY onLoad="UselessFunction()">

glenngv
01-07-2004, 03:23 AM
I don't see any error in the function. Can you post the whole code?

fredmv
01-07-2004, 03:31 AM
I'm with Glenn. The code looks correct other than the obvious missing opening <script> tag.

Roy Sinclair
01-07-2004, 03:38 PM
Actually there is a bug, you need a space after "Silly" or before "rabbit". Otherwise they'll run together as "Sillyrabbit" in the alert.

toymachine22122
01-07-2004, 05:27 PM
But when I put it in my page it says Error in the status bar and no alert comes up at all

Thermidor
01-07-2004, 05:32 PM
I'm pretty sure the problem is that you use single quotes around 'Silly' and double quotes around "rabbit Trix..."

Skyzyx
01-07-2004, 05:34 PM
If you download Mozilla (http://www.mozilla.org) (which is a MUCH better browser than IE anyways), ou can easily find the problem.

Open the Mozilla web browser, load your page, then go up to the menu and choose: Tools > Web Development > JavaScript Console. It'll tell you exactly what the problem is. It's infinitely better than Internet Explorer's debugging. :thumbsup:

Roy Sinclair
01-07-2004, 08:49 PM
Originally posted by Thermidor
I'm pretty sure the problem is that you use single quotes around 'Silly' and double quotes around "rabbit Trix..."

That has nothing to do with it.

I also see that you're missing the </head> tag which should be between the </script> and the <body> tags. I tried your script in a simple page and it works so the problem is more likely elsewhere on your page. Post the whole page (or a link to it) if you can't find the problem.

ronni_e
01-07-2004, 08:53 PM
Try this code.. It worked for me.. All I did was add the space after "Silly" and then put <script language....
<html>
<head>
<title>...</title>
<script language="JavaScript" type="">
<!-- Begin
function UselessFunction() {
var Useless = 'Silly '
alert( Useless + "rabbit, trix are for kids!" )
}
// END -->
</SCRIPT>
</head>
<BODY onLoad="UselessFunction()">

warhammerdude20
01-08-2004, 12:46 AM
well, all i can see is that at the end of the variable, and the alert, there is no ";". i know that when i miss that, the whole page is an error.

thats all i see. its good to get in the habbit of putting one of the ";" at the end of every command even if you dont really need one.

example

function whatever(){
var something = "silly"; //note the ";"
alert(something+" rabbit, trix are for kids!"); // again the";"
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum