By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 3,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

JavaScript function only works in Internet Explorer but not Firefox

P: 1
I have 4 textfields labeled "qtyA","qtyB","qtyC" and "GrandTotal". I have my calculate() function run Onchange of any of the "qty" fields and it displays it in "GrandTotal". I am trying to get my code to work on browsers other than IE but I am at a loss with everything I have tried.


Expand|Select|Wrap|Line Numbers
  1. function calculate()
  2. {
  3. totalcost = (document.orderform.getElementById("QtyA").value * "11")+
  4. document.getElementById("QtyB").value * "22" + (document.getElementById("QtyC").value * "33") ;
  5. var result = totalcost.toFixed(2);
  6. document.getElementById("GrandTotal").value = result
  7. }
Any help would be appreciated.
Oct 25 '08 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi.

How exactly do your textfields look like?
I ask because IE incorrectly uses the "name" attribute of elements when searching with document.getElementById.
If you fields use name rather than id, then that may be your problem.

I also notice you do calculations like so:
Expand|Select|Wrap|Line Numbers
  1. element.value * "11";
  2.  
It seems odd to me to deliberately use a string for calculations.
Converting the value into a number, rather than the number into a string would make much more sense:
Expand|Select|Wrap|Line Numbers
  1. parseInt(element.value) * 11;
  2.  
Oct 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.