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

ParseInt Does work in Firefox

Status
Not open for further replies.

mike10101

Vendor
May 6, 2005
13
GB
Hi there,

I have written the following javascript which works perfectly in IE but doesn't work in Firefox, I believe it this is due to passing in two variable into the function.

Can anybody shed any light?

function optionPrice(checked, value) {

if (checked == true){

document.FrmAdd.vehicleOpCost.value = parseInt(document.FrmAdd.vehicleOpCost.value) + parseInt(value) ;
document.FrmAdd.ExtrasCount.value = parseInt(document.FrmAdd.ExtrasCount.value) + 1;
}

else{

document.FrmAdd.vehicleOpCost.value -= value;
document.FrmAdd.ExtrasCount.value = parseInt(document.FrmAdd.ExtrasCount.new_val) - 1;
}
}
 
What is this? Are you making up form element attributes?
Code:
document.FrmAdd.ExtrasCount.new_val

Lee
 
The most robust syntax for using parseInt requires you pass in the base as a second parameter:
Code:
var data = parseInt("1234", 10);
In the example above I have specified base 10. If you miss this out, you may get unexpected results.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
thanks for the replies,

with regard to: document.FrmAdd.ExtrasCount.new_val. This was just a bit of old testing code I left in and have now rectified. I have also added the base parameter but still displays NaN in FF. I have added the following code as a test:

var checked, value
function optionPrice(checked, value) {
document.write (isNaN(parseInt(value, 10)));
}

FF displays: True
IE displays: False

So it would seem to me that FF is refuseing to convert the value to an iteger? are there any other ways to convert variables to integers.
 
sorted... it wasn't working in FF because I used an invalid attribute in the input tag that called the funtion. IE didn't seem to mind, however FF refused to define it. Wish I had realised that sooner.. Many thanks for your support.

Mike
 
If you ever have a problem in firefox, make sure your on the latest version (currently 2.0.0.3) and then check the error log under tools from the menu bar. It will show all errors that happened.

Bill
Oracle DBA/Developer
New York State, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top