Javascript runs fine in IE, not Firefox

I created a web form that is a table view with 15 rows and 5 colums. the bottom row and right most column are for calculated values. When a user enters a value in any of the fields, calculated values are adjusted. I have the form working perfectly in IE, but in Forefox, the calculated value fields remain blank. To keep users from modifying the totals, I set the calculated fields, disadled=“disabled”. Since disabled fields don’t pass when form is submitted via post, I created a hidden field to hold the value. The hidden field has the same name as the disabled field except the last letter of the name duplicates. I.E. PreKDiscrepancy & PreKDiscrepancyy.

Here is an example of the calculation for the first row:


DH = parseInt(document.forms(0).PreKCurrentTrained.value, 10) + parseInt(document.forms(0).PreKAbsent.value, 10);
DH = DH + parseInt(document.forms(0).PreKOptOut.value, 10);
DH = parseInt(document.forms(0).PreKEnroll.value, 10) - DH;

document.forms(0).PreKDiscrepancy.value = DH
document.forms(0).PreKDiscrepancyy.value = DH

what about the code does firefox not like?

Why are you using “disabled” and then having to create a hidden field to pass the value when “readonly” disallows entry into the field but still passes it so as to do away with your hidden field.

Why are you using “disabled” and then having to create a hidden field to pass the value when “readonly” disallows entry into the field but still passes it so as to do away with your hidden field.

Also, you didn’t say what results you get in Google Chrome, Safari or Opera. Do they produce the same result as IE or the same as Firefox?

Ok. I figured out what to do to get the JS to work, but I don’t know why the original code didn’t work

Answer:
use

 DH = parseInt(document.getElementById('PreKCurrentTrained').value, 10) + parseInt(document.getElementById('PreKAbsent').value, 10);

rather than

DH = parseInt(document.forms(0).PreKCurrentTrained.value, 10) + parseInt(document.forms(0).PreKAbsent.value, 10);

For some reason document.forms(0).element… is not supported by all browsers where as getElementById is.

Why are you using “disabled” and then having to create a hidden field to pass the value when “readonly” disallows entry into the field but still passes it so as to do away with your hidden field.

Also, you didn’t say what results you get in Google Chrome, Safari or Opera. Do they produce the same result as IE or the same as Firefox?

Also you shouldn’t be using parseInt unless you are converting between number bases. To convert a string to a number use either num = Number(str) or num = (+str);

I was using disabled fields because I want to have the fields gray’d out. Readonly looks like a regular field that is broken and not typable.

As for the other browsers your guess is as good as mine. I do not have them installed. I originally wasn’t going to bother testing in another browser since the code runs on a sharepoint site. Sharepoint sites, by default do not support browsers other that IE since the site is coded to use active x. I ran into the problem answering a question for a user who was trying to use firefox. Someday Microsoft might change the software to work in other browsers. Better to write cross browser compliant code and have it work than to have people complain and have to rework the code at a later date when I don’t remember how it works.

Unless parseInt uses a lot more processing power and slows down a page significantly, I’m not rewriting several hundred lines of cod.

Only if you don’t style it. You can use CSS to style it to look whatever way you like, just as you can style disabled fields so they don’t appear to be greyed out Youy should use CSS to define the appearance, not use the wrong HTML just because it defaults to the appearance you want…

I didn’t realize that text boxes could be styled to look greyed out, when in fact they are read only. It’s great to learn something new. I’ll have to wait for my next app to try this. No sense redesigning a form, pocessing page and the SQL server storred procedure that works.