Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help !!! code working in IE not in Firefox 1

Status
Not open for further replies.

RaceAap

IS-IT--Management
Sep 5, 2001
39
NL
Hi,

I have a piece of javascript that works very nice in IE but doesn't work in a Firefox browser..



function Check_Prod()
{
theForm = document.order_form;
var total = 0;
for ( i = 1 ; i <= nr_of_prod ; i++ ) {
if(theForm.elements['Product' + i].checked == true) {
tmp_pric = 0;
theForm.elements['price'+ i].value = theForm.elements['price_hid' + i ].value;
tmp_pric = new Number(theForm.elements['price_hid' + i ].value);
total = total + tmp_pric;
} else {
theForm.elements['price'+ i].value = "";
}
}
total = total.toFixed(2);
if (total == 0 ){
theForm.elements['Price_tot'].value = "";
} else {
theForm.elements['Price_tot'].value = total;
}

}

Thanx,

Lon
 
Change

theForm = document.order_form;

(which is IE DOM specific) to

theForm = document.forms.order_form;

(which isn't).
 
Actually, you should use the associative array syntax:

theForm = document.forms['order_form'];

Lee
 
Or if you're feeling creative...
Code:
theForm = document.getElementsByTagName("FORM")["orderForm"];

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Lee, the form document.forms['order_form'] is syntactically identical to document.forms.order_form. Or to document['forms']['order_form'] if you want an example of why this is a silly thing to say. The permanent DOM elements are not differently addressed than the impermanent ones.

The ['...'] notation is for use with variable structures or structures referring to items with broken identifiers - for instance, the use of spaces, which is allowed in name tags though not in id tags, yet a and form element name tags are directly inserted into the DOM tree. It doesn't make sense to use the document.forms but then to insist on ['order_form'] notation.
 
MOrac, thanks for your reply it solved the problem.



Thanx,

Lon
 
I was under the impression from what I've read here that some browsers only accepted the associative array format for all forms and elements references. Sorry about that.

Lee
 
<grins> Can you imagine referring to a nested media component of a CSS form by associative arrays only? *shudders*

Especially if you're paranoid and check each element exists on the way down the tree...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top