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

Include .js file inside HTML and call functions from another <script>

Hi,
I am having a strange problem...
I have an HTML file which has 2 script tags:
1) <script language="javascript" id="ABC" src="ABC.js" />
2) <script id="general" language="javascript">
function foo()
{
alert("aaa");
}
</script>

I am trying to call the "foo" function and also functions from the
"ABC.js" file.

when calling the ".js" file - functions are called fine!
however, when calling the "foo" function - I get an error! ("Object
expected")

My HTML:
<HTML>
<head>
<script language="javascript" id="ABC" src="ABC.js" />
<script id="general" language="javascript">
function foo()
{
alert("aaa");
}
</script>
<title>Test</title>
</head>
<body>
<INPUT id="Button1" type="button" value="JS1"
onclick="JSFileFunction()"></P>
<INPUT id="Button2" type="button" value="JS2" onclick="foo()"></P>
</body>
</HTML>

My ABC.js file:
function JSFileFunction()
{
alert("ABC");
}
PLZ help me.... I'm stuck!!!

Apr 5 '06 #1
12 62835
VK

Iddo wrote:
Hi,
I am having a strange problem...
I have an HTML file which has 2 script tags:
1) <script language="javascript" id="ABC" src="ABC.js" />
2) <script id="general" language="javascript">
function foo()
{
alert("aaa");
}
</script>


I have forgotten the closing tag for the external file (<script>
elements always requires closing tag).

Script element has type "text/javascript" (not language "javascript").

Script elements doesn't have id attribute.

<script type="text/javascript" src="ABC.js"></script>
<script type="text/javascript">
// your code here
</script>

Apr 5 '06 #2
Change:
<script language="javascript" id="ABC" src="ABC.js" />

into
<script language="javascript" id="ABC" src="ABC.js"></script>
That solved the problem for me (in Firefox)

Apr 5 '06 #3
Iddo wrote:
I have an HTML file which has 2 script tags:
There are no "script tags". There are (script) _elements_,
consisting of start and end tag, and optionally content.
1) <script language="javascript" id="ABC" src="ABC.js" />
MUST be at least

<script type="text/javascript" language="javascript"
src="ABC.js"></script>

HTML's SHORTTAG syntax is different from XHTML's. In HTML,

<script ... />

is equivalent to

<script ...>&gt;

First, text content is not allowed directly below the `head' element,
and second, the `script' element is not closed.
2) <script id="general" language="javascript">
Must be at least

<script type="text/javascript" language="javascript">

The `type' attribute is mandatory, and the element has no `id' attribute
(nor would it need one). The `language' attribute is deprecated in HTML
4.01, and can be safely omitted. It MUST be omitted if you declare HTML
4.01 Strict.
[...]
I am trying to call the "foo" function and also functions from the
"ABC.js" file.
when calling the ".js" file
Files cannot be called, they can be executed if they contain executable
code. But this is no file, it is a script resource (that can be saved
as a file). It can be (down)loaded, if that.
- functions are called fine!
however, when calling the "foo" function - I get an error! ("Object
expected")
It would appear that due to forced error-correction of your invalid markup,
the </script> (close) tag of the second `script' element is understood as
the close tag for the first `script' element, and any code in the second
`script' element is ignored. Hence there is no foo() method that can be
called.
<HTML>
Although not required in HTML, element type identifiers and attribute
identifiers should be lowercase always. A DOCTYPE declaration is missing
before this start tag of the `html' element.
<INPUT id="Button1" type="button" value="JS1"
onclick="JSFileFunction()"></P>
<INPUT id="Button2" type="button" value="JS2" onclick="foo()"></P>
It does not seem as if you would need an ID for either button.
There is no <P> open tag, so nothing that needs to be closed with </P>.

<URL:http://validator.w3.org/>
PLZ help me.... I'm stuck!!!


It would be best if you understood the basics of Web authoring before you
started with Web programming.
PointedEars
Apr 6 '06 #4
In article <28******************@PointedEars.de>, Thomas 'PointedEars'
Lahn <Po*********@web.de> writes
Iddo wrote:


<snip>
<HTML>


Although not required in HTML, element type identifiers and attribute
identifiers should be lowercase always.

<snip>

Why? Do you have a technical reason, or are you just being an art
critic?

John
--
John Harris
Apr 6 '06 #5
John G Harris wrote:
[...] Thomas 'PointedEars' Lahn [...] writes
Iddo wrote:
<HTML>


Although not required in HTML, element type identifiers and attribute
identifiers should be lowercase always.


Why? Do you have a technical reason, or are you just being an art
critic?


Yes. It compresses better, is less error-prone, and is good to be developed
as a habit when taking more recent markup languages into account.
PointedEars
Apr 6 '06 #6
Thomas 'PointedEars' Lahn wrote:
John G Harris wrote:
[...] Thomas 'PointedEars' Lahn [...] writes

Although not required in HTML, element type identifiers and attribute
identifiers should be lowercase always.


Why? Do you have a technical reason, or are you just being an art
critic?


Yes. It compresses better, is less error-prone, and is good to be developed
as a habit when taking more recent markup languages into account.


Not sure how it would "compress better" (or why that would be relevant)

Consistency, in either direction, would be less error-prone, IMO.

The third point is probably the best case to make: I'm not up on all the
specs, but I understand that some of them REQUIRE lower-case tags. If
you're already in that habit, it's less likely you'll screw something up
if you ever have need to use another doctype.
Apr 6 '06 #7
Tony a écrit :
Thomas 'PointedEars' Lahn wrote:
John G Harris wrote:
[...] Thomas 'PointedEars' Lahn [...] writes
Although not required in HTML, element type identifiers and attribute
identifiers should be lowercase always.
Why? Do you have a technical reason, or are you just being an art
critic?

Yes. It compresses better, is less error-prone, and is good to be
developed
as a habit when taking more recent markup languages into account.

Not sure how it would "compress better"


Probably because most the text of a page being lowercase, you may have
better compression with tag names also in lowercase... (wild guess) (and
totally ot).

Apr 7 '06 #8
On Sat, 08 Apr 2006 00:57:16 +0200, Bruno Desthuilliers wrote:
Tony a écrit :
Thomas 'PointedEars' Lahn wrote:
John G Harris wrote:
[...] Thomas 'PointedEars' Lahn [...] writes
>
> Although not required in HTML, element type identifiers and attribute
> identifiers should be lowercase always.

Why? Do you have a technical reason, or are you just being an art
critic?

Yes. It compresses better, is less error-prone, and is good to be
developed
as a habit when taking more recent markup languages into account.


Not sure how it would "compress better"


Probably because most the text of a page being lowercase, you may have
better compression with tag names also in lowercase... (wild guess) (and
totally ot).


Huh? In ASCII all characters are seven bit.
--
The USA Patriot Act is the most unpatriotic act in American history.

Apr 7 '06 #9
Bruno Desthuilliers wrote:
Tony a écrit :
Thomas 'PointedEars' Lahn wrote:
John G Harris wrote:
[...] Thomas 'PointedEars' Lahn [...] writes
> Although not required in HTML, element type identifiers and attribute
> identifiers should be lowercase always.
Why? Do you have a technical reason, or are you just being an art
critic?
Yes. It compresses better, is less error-prone, and is good to be
developed as a habit when taking more recent markup languages into
account. Not sure how it would "compress better"


Probably because most the text of a page being lowercase, you may have
better compression with tag names


and attribute names (but not attribute values, of course)
also in lowercase... (wild guess)
Exactly. Redundancy counts.
(and totally ot).


ACK
PointedEars
Apr 7 '06 #10
On Fri, 07 Apr 2006 22:27:21 +0200, Thomas 'PointedEars' Lahn wrote:
Bruno Desthuilliers wrote:
Tony a écrit :
Thomas 'PointedEars' Lahn wrote:
John G Harris wrote:
> [...] Thomas 'PointedEars' Lahn [...] writes
>> Although not required in HTML, element type identifiers and attribute
>> identifiers should be lowercase always.
> Why? Do you have a technical reason, or are you just being an art
> critic?
Yes. It compresses better, is less error-prone, and is good to be
developed as a habit when taking more recent markup languages into
account.
Not sure how it would "compress better"


Probably because most the text of a page being lowercase, you may have
better compression with tag names


and attribute names (but not attribute values, of course)
also in lowercase... (wild guess)


Exactly. Redundancy counts.


What compression utilizing redundancy occurs between the web server and
the browser?

--
The USA Patriot Act is the most unpatriotic act in American history.

Apr 7 '06 #11
VK

Ivan Marsh wrote:
Huh? In ASCII all characters are seven bit.


Huh? The US may have some defaults, but not up to the point of using
seven-bit bytes :-)

ASCII characters are the conventional 8-bit bytes, but only 7 bits are
used, which brings the total amount of possible combinations to 127
(low part of ASCII table).

Apr 8 '06 #12
VK wrote:
Ivan Marsh wrote:
Huh? In ASCII all characters are seven bit.
Huh? The US may have some defaults, but not up to the point of using
seven-bit bytes :-)


And even if they had, the statement would be irrelevant regarding data
compression. For it was not argued that a lowercase character required
less bits to be encoded (on the contrary, if ASCII was not the fixed-width
encoding that it is, lowercase characters would require _more_ bits to be
encoded than uppercase characters, because uppercase characters have
_lower_ code points than lowercase characters in ASCII).
ASCII characters are the conventional 8-bit bytes, but only 7 bits are
used,
False. The eighth bit has been (is?) used, too, but not for the character
code.
which brings the total amount of possible combinations to 127
(low part of ASCII table).


False. The number is 2^7 = 128, of course. From 0 to 127 decimal
(7F hexadecimal).

<URL:http://en.wikipedia.org/wiki/ASCII>
PointedEars
Apr 8 '06 #13

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

Similar topics

2
by: Madhav | last post by:
I have the following statements in my script. ---------------------------------------------------------- textToWrite = "<HTML> \n" + "<HEAD> \n" + "<TITLE>Calendar</TITLE> \n" + "<SCRIPT...
1
by: John MacIntyre | last post by:
Hi, I am having a problem executing server side javascript. For some reason the script tag is ignored when the runat=server is combined with the src attribute. The code is being used client...
10
by: Blue® | last post by:
I would like to call the content of content.htm (containing only HTML codes) into index.htm. This is usually done by renaming index.htm to index.shtml and use this tag: <!--#include...
9
by: Howard | last post by:
Hello I need some help with this. I want to assign the content of a static txt/html file to my string a. <script runat="server" language="C#"> private void Page_Load(object sender,...
9
by: sam.s.kong | last post by:
Hello! I have a JavaScript code like the following. <script> var s = "</script>"; ....
21
by: hemant.singh | last post by:
Hello all, I am try'g to send window.location.href to the server script who will generate dynamic javascript according to the referral name comg in as param Now bcz <script language="javascript"...
5
by: David Thielen | last post by:
Hi; Almost all of the Quick Starts show the code in the .aspx file inside a <script> instead of in a seperate .aspx.cs file. My instinct is that the code should be in a seperate file to keep the...
44
by: rhythmace | last post by:
W3C HTML validator passes this: .... <script type="text/javascript" src="foo.js"> <script type="text/javascript"> ....script in here... </script> ....
3
by: kal | last post by:
Hi I have a aspx page that has a function in a script tag which is called from code in a javascript src file that is loaded in the <headtag. the thing is that that browser complains that it...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.