Where to put the Script Tags
The Script Tag and HTML
So, cut your script out of the BODY section, and paste it into the HEAD section. Like this:
Save your work, and then view the results in your browser. Did it make a difference? No, it did not. But rest assured that your script was dealt with before anything in the BODY section.
You can also put your scripts into HTML tags. Here's the document.write() code inserted into a Form's Button code:
OnClick = "document.write('Hello World')"
OnClick is an event that can be applied to buttons (amongst other things.) We'll get to Events later, but for now, note that the same code we wrote earlier then goes after an equals sign ( = ). Or is it the same code? Have you spotted the difference?
So what have we learnt so far? We've learnt this:
The Pop-up message box
We've seen one way to display text - with the write() method of document.
Another way to display text (and numbers) is with a little pop-up box.
your users when they don't fill in your forms correctly. Here's a picture
The code for an Alert box is quite simple. It's this:
alert("That was not a proper email address")
Notice the cunning use of "alert" for an alert box? The message you want to get over to your users goes between the two brackets. Surround your text message with double quotes, or single quotes if you're putting it after an equals sign in a HTML element.
OnClick = "alert('That was not a proper email address')"
All right, now that we know how to nag our users with pop-up boxes and written messages, what else can we do? Lots, actually. Let's have a look at that document thing again.