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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pls Help!! Error in Explorer 4.0 but not Netscape!

Status
Not open for further replies.

hossf

Technical User
Jan 5, 2002
3
US
I am having hard time with the code below. I tworks in Netscape but generates a JavaScript error in Explorer 4.0. In particular it says that document.form1.elements is not an object!

What I am trying to do is add together the quantities in a varaiable number of textboxes which the user enters and then put them in the qt field. The len variable gives us the number of textboxes. The function is triggered by an ONCHANGE event in the textboxes so that as the user tabs from one field to another the qt field is updated.


function add() {
sum=0;
len=document.form2.size_array.value.split(",").length
for (i=0; i<len; ++i){
if (document.form1.elements.value == &quot;&quot;){document.form1.elements.value = &quot;0&quot;
}
sum+=eval(document.form1.elements.value)
}
document.form1.qt.value=sum.toString()
}

Thank you for helping out on this.

Hoss
 
I am not sure exactly what's going on here but I surmise the problem is elements needs to be subscripted with .

Looks like 'len' should be the number of elements in form1. Also, what's going on with form2?
 
i think u probably have a typo with by accidentally typing form2 when u meant form1.
 
I am sorry I had TGML going on the post so the code came out wrong. Here it is again:

function add() {
sum=0;
len=document.form2.size_array.value.split(&quot;,&quot;).length
for (i=0; i<len; ++i){
if (document.form1.elements.value == &quot;&quot;){document.form1.elements.value = &quot;0&quot;
}
sum+=eval(document.form1.elements.value)
}
document.form1.qt.value=sum.toString()
}


I am using form2 to hold some values using hidden fields. One field holds a string of sizes eg &quot;XS,S,M,L,XL&quot; (this page is used for ordering clothing across a size range.) The len variable then gets the number of size elements from this string.

The whole thing works perfectly in Netscape but Explorer is giving errors.

Hoss
 
there is a pre-defined add() function in javascript. could that be the problem ?
 
bluebytez:

I changed add() to sumup() and still got the same error. But you got me thinking that IE was getting something mixed up so I changed all the form1 and form2 to formone and formtwo and this solved the problem! And people get grouchy with Netscape!!!

Anyway, many, many THANKS for putting me on the right track.

hoss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top