Javascript fails in Firefox (OK in IE)

A

ajr121

The following cgi generated html page has the following Javascript in
the Body section:-

<script language="JavaScript" type="text/javascript">
<!-- Begin
function eHistorical()
{
document.F1.action="http://www.somedomain/historicalitems.htm";
F1.submit();
}

//-->
</script>

Further down the page we have the following Form :-

<form name="F1">
<p align="right">
<input type = "button" name="B2" value = "Historical Items" onclick
="eHistorical()">
</p>
</form>

The page loads OK but when button B2 it clicked the following error is
reported by Firefox :-

"F1 is not defined"

Any thoughts - it works fine in IE.
 
S

Stevo

document.F1.action="http://www.somedomain/historicalitems.htm";

Further down the page we have the following Form :-

<form name="F1">

The page loads OK but when button B2 it clicked the following error is
reported by Firefox :-

"F1 is not defined"

Any thoughts - it works fine in IE.

It's IE that's incorrectly allowing you to take that shortcut of
addressing it as document.F1. Ideally you should be using
document.forms.F1 instead.
 
S

SAM

R

Richard Cornford

The following cgi generated html page has the following
Javascript in the Body section:-

<script language="JavaScript" type="text/javascript">
<!-- Begin
function eHistorical()
{
document.F1.action="http://www.somedomain/historicalitems.htm";
F1.submit();
}

//-->
</script>

Further down the page we have the following Form :-

<form name="F1">
<p align="right">
<input type = "button" name="B2" value = "Historical Items"
onclick ="eHistorical()">
</p>
</form>

The page loads OK but when button B2 it clicked the
following error is
reported by Firefox :-

"F1 is not defined"

Any thoughts - it works fine in IE.

Factors that could influence this behaviour would be outside of the code
you have posted. If you want an answer we will need to see the context.

However, don't do that. There is no need to involve javascript in this
at all, and if you don't you will certainly not get any javascript
issues. Consider:-

<form action="http://www.somedomain/historicalitems.htm">
<p align="right">
<input type="submit" name="B2" value="Historical Items">
</p>
</form>

- without any scripting at all.

Richard.
 
T

Thomas 'PointedEars' Lahn

JFTR: The `action' attribute is #REQUIRED, and missing here.
<p align="right">
<input type = "button" name="B2" value = "Historical Items"
onclick ="eHistorical()">
</p>
</form>

The page loads OK but when button B2 it clicked the
following error is
reported by Firefox :-
[...]

[...] There is no need to involve javascript in this
at all, and if you don't you will certainly not get any javascript
issues. Consider:-

<form action="http://www.somedomain/historicalitems.htm">
<p align="right">
<input type="submit" name="B2" value="Historical Items">
</p>
</form>

To satisfy the requirements of HTML 4.01 Strict (else you would not need any
of it), one should use DIV instead of P here, for there is no running text
inside a paragraph. Also, CSS text-align:right MUST then be used instead of
the deprecated `align' attribute; with HTML 4.01 Transitional, it only
SHOULD be used.

Another variant, IMHO the better one, is not to use a form in the first
place, and to use a styled hyperlink instead. That way the user could also
be informed about the visit status of the target resource in an accessible way.
- without any scripting at all.

Full ACK.


PointedEars
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top