Re: More than a single script block within a single HEAD and BODY



Water Cooler v2 wrote:
Questions:

1. Can there be more than a single script block in a given HEAD tag?

Inside a script *element*, yes. You can have as many as you like.


2. Can there be more than a single script block in a given BODY tag?

Inside a script *element*, yes. You can have as many as you like.


To test, I tried the following code. None of the script gets executed.

Because there are errors in the and HTML - *always* start with valid HTML. The W3C HTML validator lets you paste markup directly into the validation form.

<URL:http://validator.w3.org/>


Can someone please give me a direction as to what I may be missing?

See below.


<!--The purpose of this program will be to:

1. Use an external script;
2. To use more than one SCRIPT tag inside a HEAD tag; and
3. To use more than one SCRIPT tag inside a BODY tag.
-->

<HTML>

<HEAD>

<SCRIPT language="JavaScript type="text/javascript">

The language attribute is deprecated, remove it. Keep type.


<!--

Don't use HTML comments inside script elements, they are useless.


document.write("This is the first of the script tags within the HEAD
tag.");

The result of the document.write will be placed immediately after the script element. It is still inside the head, the browser isn't supposed to display any content in the head so the browser must decide whether to employ error correction and end the head and display the text, or continue the head to the closing tag and not show the text.

Whatever choice is made may be inconsistent across different browsers.


-->

This is a meaningless script statement. To use HTML comments at all, the closing tag should be quoted:

// -->

But just don't use them.


</SCRIPT>

<SCRIPT language="JavaScript type="text/javascript">
<!--
document.write("This is the second script tag within the HEAD
tag.");
-->
</SCRIPT>

Comments as above.



<SCRIPT language="JavaScript type="text/javascript"
src="TheExternalScript1.js"></SCRIPT>

What is in the external file? You should have a title element inside the head. Putting one right at the top might encourage error correction to move the closing head tag up higher and move the body up too - causing the text written by document.write to be displayed (or not).

</HEAD>



<BODY>
<SCRIPT language="JavaScript type="text/javascript">

Here you are missing the closing quote after language="JavaScript

That will cause a variety of errors, essentially reversing the sense of following double quotes.

<!--
document.write("\

It is legal to quote new lines, but much preferred to use concatenation:

document.write("The purpose ..."
+ "<br>1. Use..."
+ "<br>2. To..."
);

The purpose of this program will be to:<BR/><BR/>\

Don't use XHTML style empty element tags in what is HTML (despite the missing, required DOCTYPE element).

Forward slashes "/" within document.write strings should be quoted because they should indicate the close of the script element, most browsers tolerate them regardless.

\
1. Use an external script;<BR/>\
2. To use more than one SCRIPT tag inside a HEAD tag; and<BR/>\
3. To use more than one SCRIPT tag inside a BODY tag.<BR/>");

Fix those errors and apply to the rest of the page.

[...]


--
Rob
.



Relevant Pages

  • Re: Http code that precedes the html tags
    ... however when I try to put it before the <HTML> tag it does not work. ... I don't understand what format the http code takes. ... contains permittted HEAD elements ... The only thing permitted before the tag is the Doctype Declaration, which normally should be this one: ...
    (alt.html)
  • Re: encoding of scripts
    ... is not valid HTML - the fact that there is an end script tag in quotes ... causes the parser to stop recognising the script. ... The fact that there is an end tag causes that. ... By HTML 4.01 rules, yes. ...
    (comp.infosystems.www.authoring.html)
  • Need Help with Registering Client Scripts
    ... I assume the second script is a start-up script since it is not a callable function. ... I see neither registered scripts are placed within the <head> tag. ... I need to put this in a control that really should register the scripts in an organized way. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Need Help with Registering Client Scripts
    ... The sample contains the following within the <head> tag: ... I assume the second script is a start-up script since it is not a callable ... I need to put this in a control that really should register ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Frontpage inserts unwanted location data into all .htm files
    ... In your case the script tag is inside of the BODY tag and being included w/o adjustment ... That tag belongs in the HEAD section of a page so remove it from you shared border page and put it in the HEAD section of all pages ...
    (microsoft.public.frontpage.client)

Loading