[Javascript] String -> Number impossible

Peter Brunone peter at brunone.com
Tue Aug 22 00:25:26 CDT 2006


		What leads you to believe that it is a string, even after parseFloat?

> total = total+(array_prices[i])*(2);// this value works here, but I
> hardcoded it 

    I'm curious about this... you're assigning the array elements as strings (i.e. with quotes) rather than as integers.

Peter

				From: "Marcelo Wolfgang" grillo at gmail.com

Hi list,

First forgive me for posting code up in the email, there's no online
page that I can show the script.
I'm having a terrible, like 2 hours wasted on this terrible error,
trying to figure this out:
Here's the code:

array_prices = new Array();
array_prices[1] = '115'; //these values are coming from a db
array_prices[2] = '95';

function getCheckedValue(radioObj) {
	var radioLength = radioObj.length;
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
		return radioObj[i].value;
		}
	}
}

function updateTotal(){
	total = 0;
	totalField = document.getElementById('valorOnlyNumber');
	for (i=1; i < array_prices.length; i++){
		total = total+(array_prices[i])*(2);// this value works here, but I
hardcoded it
	}
	rdVal = getCheckedValue(document.frm_calcShipping.valFrete);
	if (rdVal != 0){
		total = total+rdVal;
	}
	totalField.innerHTML = total;
}

and these are my radios:

name="valFrete" />R$ 6,70

name="valFrete" />R$ 7,20

name="valFrete" />R$ 12,60

name="valFrete" />R$ 18,60

R$ 210.00

+++++++++++++++++++++
The problem is that rdVal is always a string, I've tried

rdVal = parseFloat('getCheckedValue(document.frm_calcShipping.valFrete)')

still a string

I can't figure out what to do please someone advice

TIA
Marcelo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20060821/729e4671/attachment.htm>


More information about the Javascript mailing list