PDA

View Full Version : Where does Java Script go???


Byclops
08-23-2002, 09:39 AM
Hey guys

If this is the standard lay out of a document....


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<HTML>
<HEAD>
<TITLE>The document title</TITLE>
</HEAD>
<BODY>
<H1>Main heading</H1>
<P>A paragraph.</P>
<P>Another paragraph.</P>
<UL>
<LI>A list item.</LI>
<LI>Another list item.</LI>
</UL>
</BODY>
</HTML>



...then where does a Script fit into it???



The page in question is - http://www.moneycare.com.au//Pages/topbar.html

It all works ok - but i'm pretty sure the code isnt quite as "clean" as it shoudl be....and the validator I am using concurs with that :)


Thanks guys

torrent
08-23-2002, 10:58 AM
Eek! You have the javascript placed before the <html> tag. Generally javascript either goes anywhere between the <head></head> tags or in the main body of the code. If you are writing javascript functions or the javascript does not need specific placement within the document's content, then place it all between the <head></head> tags (as in your case).

Placements between <head> tags or <body> tags are equally valid.

Byclops
08-23-2002, 09:57 PM
Originally posted by torrent
Eek! You have the javascript placed before the <html> tag. Generally javascript either goes anywhere between the <head></head> tags or in the main body of the code. If you are writing javascript functions or the javascript does not need specific placement within the document's content, then place it all between the <head></head> tags (as in your case).

Placements between <head> tags or <body> tags are equally valid.

cool thanks for that
i thought it might be the case

i am still getting one error when validating though -


Line 6, character 30:
<script language="JavaScript">
^
Error: required attribute TYPE not specified


Does anyone know what this is referring to??

Jon Hanlon
08-24-2002, 12:48 AM
The full syntax is
<script language="javascript" type="text/javascript">

kdjoergensen
09-03-2002, 10:32 AM
Since your doctype statement indicates to the browser that compliance with standards must be a strict compliance, then your syntaxes must be in compliance with the standards, also.

e.g if you use incorrect syntax or proprietary code (e.g. code supported by a particular browser, but which is not recognized by the w3c as 'standards') the browser will give an error.

The correct syntax is Jon states, or untill you are sure you want to use strict compliance with standards I suggest you change your doctype declaration to:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


That will allow you to use more flexible formatting, such as

<script language="javascript">


The problem with using strict adherrence is that your code no longer is backwards compatible. Generally it is easier to learn HTML, DHTML and Javascript if you start off with the above doctype and once you get more familiar, then change to the strict doctype and code accordingly.