473,320 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

Questions:

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

To test, I tried the following code. None of the script gets executed.
Can someone please give me a direction as to what I may be missing?

Thanks.

<!--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">
<!--
document.write("This is the first of the script tags within the HEAD
tag.");
-->
</SCRIPT>

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

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

<BODY>
<SCRIPT language="JavaScript type="text/javascript">
<!--
document.write("\
The purpose of this program will be to:<BR/><BR/>\
\
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/>");
//-->
</SCRIPT>

<P>Some intermittent text.</P>

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

<P>More HTML text.</P>

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

<P>More and more HTML.</P>

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

<P>Finally, the concluding part of the HTML text.</P>

</BODY>

</HTML>

Apr 18 '06 #1
3 2931
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
Apr 18 '06 #2
Many thanks, Rob. Mike, on another thread (two threads below) had
advised me with the same invaluable tips as you've given. Thank you
very much. I will incorporate them in any code I write from now on. I
wrote this snippet before I read the two replies (yours and Mike's).

I am sorry I forgot to mention that I had two external script files
with the same names as the references above (TheExternalScrip1.js and
TheExternalScript2.js) so there wasn't any problem with that. In the
external files, I had just written a document.write statement each.

I spotted the cause of the bug. I had not terminated the string
"JavaScript" in any of the declarations of the opening SCRIPT tag, like
so:

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

In any case, I'll omit the language attribute and heed to the other
advise you've mentioned as well. Thanks again.

Apr 18 '06 #3
Water Cooler v2 wrote:
Questions:

1. Can there be more than a single script block in a given HEAD tag?
yes
2. Can there be more than a single script block in a given BODY tag?
yes
To test, I tried the following code. None of the script gets executed.
Can someone please give me a direction as to what I may be missing? <HTML>

<HEAD>

<SCRIPT language="JavaScript type="text/javascript">
A) language is deprecated
B) *** you have no closing quote after "JavaScript
*** That would be a major contributor to your problem
*** NOTE: This is repeated on every <script> tag you use
<!--
Unnecessary, and could potentially cause problems
document.write("This is the first of the script tags within the HEAD
tag.");
Have you tried using alert() instead of document.write() ? I suspect
you'll find it works better.
-->
As-is, this would cause an error, and probably cause the javascript to
stop executing.
</SCRIPT>


All the same comments apply to all subsequent <script> tags.
Apr 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ed Brandmark | last post by:
I have a tag of the form <SCRIPT LANGUAGE="JavaScript1.1" SRC="foo.js"..... and was wondering if this delays the loading of my page until that file foo.js downloads. It seems that if I place...
2
by: Dennis | last post by:
This may be easy for most but I can't get this thing to work. I believe I followed all the instructions but when I click on the link no window opens just the default IE page cannot display. Here is...
2
by: Brian | last post by:
Hi all. I have a bunch of pages that reference an external script from the head section. I'd like to add additional <script> elements to the pages' bodies, but I can't edit the pages...
1
by: Rob | last post by:
Access Gurus, This script was used to view the reports on the web by choosing a date on or before the current day.Recently it stopped working and i am not able to figure where the problem is. ...
1
by: joe | last post by:
I need to call javascript code from within body block. The below code runs fine will I run into problem with some browsers or is there a better way? <html> <head> <meta http-equiv="Content-Type"...
1
by: Alex Maghen | last post by:
I've been using my installed VS 2005 for several months with no problem. Suddenly, something strange is happeneing and I'm not sure if it's something I'm missing in ASP.NET or something that's...
5
by: CES | last post by:
All, I was hoping that someone might be able to help me with a few questions on Aligning Block Elements properly... Basically I have a row that has a fixed width of 900px. Within the row their is...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.