473,396 Members | 1,997 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,396 software developers and data experts.

noob problem including javascript files

I'm pretty weak when it comes to Java script, hopefully someone will
take mercy on my sole and explain this to me. How come on the following
HTML page, when I have my first script tag commented out, my button
calls my OnClick function. However if I uncomment the first script tag,
I get the following error: Button1_onclick is not defined

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test Page</title>
<script
src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAPJi8eZfg6MuV 41P4Pp2gBhS3x1YvtzkSpxxqYWsb5fvYGd6L2BTQiQ9EkPuUXf JDw5lGzN8Oyx1qcg"
type="text/javascript"/>
<script language="javascript" type="text/javascript">
// <!CDATA[
function Button1_onclick()
{
alert("Girls are Pretty!!");
return false;
}
// ]]>
</script>
</head>
<body>
<input id="Button1" type="button" value="button"
onclick="return Button1_onclick()" />
</body>
</html>

Thanks
Josh

Nov 25 '06 #1
3 1602


On 25 Nov., 18:47, "Mr. Roper" <elebeo...@gmail.comwrote:
I'm pretty weak when it comes to Java script, hopefully someone will
take mercy on my sole and explain this to me. How come on the following
HTML page, when I have my first script tag commented out, my button
calls my OnClick function. However if I uncomment the first script tag,
I get the following error: Button1_onclick is not defined

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test Page</title>
<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAPJi8eZfg..."
type="text/javascript"/>
<script language="javascript" type="text/javascript">
// <!CDATA[
function Button1_onclick()
{
alert("Girls are Pretty!!");
return false;}// ]]>
</script>
</head>
<body>
<input id="Button1" type="button" value="button"
onclick="return Button1_onclick()" />
</body>
</html>

Thanks
Josh
First add an end tag for every script tag:

<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAPJi8eZfg..."
type="text/javascript"/></script>

Ajaxian told about problems in Safari using this (correct) syntax.

Secondly take away the language="" attribute from any script.

Thridly put the // ]]in a new line.

Does it work now?

Andi

Nov 25 '06 #2
Changing how I closed the script tag did the trick. Guess I'm use to
short handing XML where something like <script type='xxx'/is the same
as <script type='xxx'></script>

Thanks for your help!!!
webEater wrote:
On 25 Nov., 18:47, "Mr. Roper" <elebeo...@gmail.comwrote:
I'm pretty weak when it comes to Java script, hopefully someone will
take mercy on my sole and explain this to me. How come on the following
HTML page, when I have my first script tag commented out, my button
calls my OnClick function. However if I uncomment the first script tag,
I get the following error: Button1_onclick is not defined

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test Page</title>
<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAPJi8eZfg..."
type="text/javascript"/>
<script language="javascript" type="text/javascript">
// <!CDATA[
function Button1_onclick()
{
alert("Girls are Pretty!!");
return false;}// ]]>
</script>
</head>
<body>
<input id="Button1" type="button" value="button"
onclick="return Button1_onclick()" />
</body>
</html>

Thanks
Josh

First add an end tag for every script tag:

<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAPJi8eZfg..."
type="text/javascript"/></script>

Ajaxian told about problems in Safari using this (correct) syntax.

Secondly take away the language="" attribute from any script.

Thridly put the // ]]in a new line.

Does it work now?

Andi
Nov 26 '06 #3
webEater wrote:
Mr. Roper wrote:
<snip>
><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Test Page</title>
<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAPJi8eZfg..."
>type="text/javascript"/>
<script language="javascript" type="text/javascript">
// <!CDATA[
function Button1_onclick()
{
alert("Girls are Pretty!!");
return false;}// ]]>
</script>
<snip>
First add an end tag for every script tag:

<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAPJi8eZfg..."
type="text/javascript"/></script>

Ajaxian told about problems in Safari using this (correct) syntax.
This is not a 'correct' syntax in HTML, and it is the HTTP content type
header that decides whether a document is HTML or XHTML. Any DOCTYPE
employed in the document is irrelevant to how the browser will interpret
the document if it is sent with a content type header of text/html; the
document will be interrupted as tag-soup HTML and many HTML rules apply,
including the non-optional nature of the SCRIPT element's closing tag.
Secondly take away the language="" attribute from any script.

Thridly put the // ]]in a new line.
<snip>

Why? The end-of-line comment makes it irrelevant in an HTML document. It
would make more sense to recommend removing the pointless <!CDATA[ - ]]>
stuff entirely (especially as it is incorrect anyway as there is an
opening square bracket missing)?

Richard.
Nov 26 '06 #4

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

Similar topics

8
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is,...
9
by: Trenqo 0 | last post by:
I'm looking for a way to include javascript files from within a ".js" file. This would allow me to only need to link to one ".js" file, and yet still organize my functions into non gargantuan files...
4
by: areese801 | last post by:
i am using a website with a form that passes criteria to a javascript to run a query rather than just appending my criteria to parts of the URL. i need to import a bunch of records into MS...
4
by: Mason Barge | last post by:
I'm learning how to build a website. So far I've gotten pretty good with HTML, CSS, and Paint Shop Pro, and I'm currenly learning the basics of Javascript. I'm hoping, eventually, to build and...
42
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
8
by: sore eyes | last post by:
Hi I just downloaded the free Watcom compiler and am having a little trouble with File IO http://www.openwatcom.org/index.php/Download I downloaded the following example, commented out the...
6
by: Lang Murphy | last post by:
I'm baaaaack... some of you answered a question I had last week. Only problem is: I'm a dope who doesn't understand most of what y'all posted. Raw noob when it comes to .Net and C#. So I'm going...
1
by: vunet | last post by:
What's the possible disadvantage of including JavaScript files within a JavaScript file? Why I needed it? For the sake of easy management, perhaps? Any load speed disadvantage? Example below: ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.