Forum Moderators: open

Message Too Old, No Replies

Javascript not working in Firefox

Error variablename is not defined

         

tenerifejim

2:10 pm on Nov 3, 2005 (gmt 0)

10+ Year Member



All,

I am having some problems calling functions in Firefox:


<html>
<head>
<script language="JavaScript1.2" type="text/JavaScript1.2">
function afunction(){
alert('hello!');
}
</script>
</head>
<body>
<a href="javascript:afunction();">call function</a>
</body>
</html>

This throws 'afunction is not defined' in Firefox, but not IE. Any ideas why?

tenerifejim

2:47 pm on Nov 3, 2005 (gmt 0)

10+ Year Member



Don't worry I solved it. Pesky DreamWeaver!

It is the script tags that were the problem. I remove the 1.2 from the language and type attributes and it works fine. has anyone any ideas as to why?

Bernard Marx

3:00 pm on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In this case, it wasn't the language attribute - although using it, especially with 1.2 isn't a good idea anyway.

It's the type

"text/JavaScript1.2"

Your browser doesn't recognise that type attribute (expects "text/javascript"), so the block isn't executed, and afunction doesn't exist.

Better to put no type attribute at all than an incorrect one!

Fotiman

3:51 pm on Nov 3, 2005 (gmt 0)

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



Also, don't include the language attribute... it's not valid. :) Here's what your script tag should look like:

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

tenerifejim

11:57 am on Nov 4, 2005 (gmt 0)

10+ Year Member



Have you guys got any idea why DreamWeaver MX would auto generate those tags? Are they at all valid in any broswer? It seems a but strange that it would do it at all.