Forum Moderators: phranque

Message Too Old, No Replies

Empty Javascript Tags

Is there a work around, or did I miss something?

         

sparrow

3:20 pm on May 11, 2002 (gmt 0)

10+ Year Member



I call an external script here;

<script language ="JavaScript" type="text/javascript" src="external.js"></script>
<script type="text/javascript">Function()</script>

Every time I place the "Function()" in the first tag, the function is never passed. It works fine like this but, page validation shows a warning for an empty tag.

Should I being doing something different here?

txbakers

6:59 pm on May 11, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You didn't syntax the function correctly:

<script type="text/javascript">
Function(){
commands here
}

</script>

sparrow

8:47 pm on May 11, 2002 (gmt 0)

10+ Year Member



Thanks for the help. :)

What your telling me is for a function within the page.

I am trying to call the function form the external.js page.

It works fine they way it is displayed, it just will not validate 100% because the first line is an empty tag.

Why is that?

jdMorgan

2:47 am on May 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a ";" or a newline?

Function();</script>

-or-

Function()
</script>

(just a guess)

Cheers!
Jim

txbakers

3:35 am on May 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm still confused as to what you are doing. Is there a URL we can look at that has this code?

keyplyr

5:49 am on May 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To call an external script, just use:

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

All your code should be contained in the above file. This second part is not needed and is causing the error:

<script type="text/javascript">Function()</script>

sparrow

12:45 pm on May 13, 2002 (gmt 0)

10+ Year Member



keyplyr

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

Contains mulitple functions called through out the page.

It is also the line that the "empty tag" warning is reported on. Because there is nothing between <script>and </script>

If I remove the second line
<script type="text/javascript">Function()</script>

This function will not be called. It is actually the function that identifies the browser, screen size, etc, which will return the appropriate style sheet to used.

It is really is not a big deal, because the page is displayed correctly, it's just one of those obnoxious things when you validate a page and you are returned a "warning" for having an empty tag. That's all, and I was wondering if there was a better way of writing it.

Thanks for your help. ;)

jdMorgan

5:17 pm on May 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sparrow,

It looks to me like your use of the word "Function" is what threw many of us off the trail. I know I initially confused what I now believe you meant as "my_function();" (function invocation) with function { ... }; (function declaration).

This just looks like your validator doesn't recognize external scripts. Maybe you can make it happy with a "//" comment tag between the <script> and </script> tags, or something similar... Or maybe the bug is more subtle, and it might recognize what you want if you swap the "src" declaration and the "type" declaration inside the <script> tag, and give it the "src" first.

What validator are you using?

...Still just guessing but hope this helps.
Jim

keyplyr

9:09 am on May 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry, just trying to be of help.

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

has never caused an "empty tage" warning for me at W3C, the Val here or CSE lite.

sparrow

1:46 pm on May 14, 2002 (gmt 0)

10+ Year Member



I validate just fin in W3C, which in all actuality is the only one that counts.

Hitdoctor and I think Bobby, give warning errors of empty tags.