Why error in IE not Firefox?

J

Jeremy

Tell I'm stupid if you will.... the following works on Firefox but not
in IE (6) - gives an error

Line 16 Char 3
Illegal Assignment

<html>
<body>
<form name=f>
<input type=text name=inp>
&nbsp;
<input type=button value=convert onclick="conv();">
&nbsp;
<input type=text name=out>
</form>
<script type="text/javascript">
function conv()
{
f=document.forms[0].inp;
alert ("input"+ f.value);
}
</script>
</body>
</html>

Also, any good javascript debuggers available free of charge?
 
R

RobG

Jeremy said:
Tell I'm stupid if you will.... the following works on Firefox but not
in IE (6) - gives an error

Line 16 Char 3
Illegal Assignment

<html>
<body>
<form name=f>

IE makes the name of the form as a global variable, Firefox doesn't.
<input type=text name=inp>
&nbsp;
<input type=button value=convert onclick="conv();">
&nbsp;
<input type=text name=out>
</form>
<script type="text/javascript">
function conv()
{
f=document.forms[0].inp;

Here you create another global variable called 'f' that in IE conflicts
with the already declared f. It seems the form wins and the assignment
of the input reference is not achieved.

The simple solution is to include the keyword 'var' to make f a local
variable:

var f = document.forms[0].inp;

alert ("input"+ f.value);
}
</script>
</body>
</html>

Also, any good javascript debuggers available free of charge?


Use the javascript console in the Geko-based browsers (Firefox, Mozilla,
Netscape, et al).
 
J

Jeremy

Jeremy said:
Tell I'm stupid if you will.... the following works on Firefox but not
in IE (6) - gives an error

Line 16 Char 3
Illegal Assignment

<html>
<body>
<form name=f>

IE makes the name of the form as a global variable, Firefox doesn't.
<input type=text name=inp>
&nbsp;
<input type=button value=convert onclick="conv();">
&nbsp;
<input type=text name=out>
</form>
<script type="text/javascript">
function conv()
{
f=document.forms[0].inp;

Here you create another global variable called 'f' that in IE conflicts
with the already declared f. It seems the form wins and the assignment
of the input reference is not achieved.


Oh thanks very much for that.


Use the javascript console in the Geko-based browsers (Firefox, Mozilla,
Netscape, et al).

OK thanks I have played with these already - unfortunately when the
error only shows in IE.... :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top