469,904 Members | 2,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

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 1442


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Rich Grise | last post: by
9 posts views Thread by Trenqo 0 | last post: by
4 posts views Thread by areese801 | last post: by
4 posts views Thread by Mason Barge | last post: by
9 posts views Thread by davetelling | last post: by
8 posts views Thread by sore eyes | last post: by
6 posts views Thread by Lang Murphy | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.