[Javascript] String -> Number impossible
Marcelo Wolfgang
grillo at gmail.com
Mon Aug 21 23:45:20 CDT 2006
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:
<pre>
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;
}
</pre>
and these are my radios:
<div id="normal-mgprrjscCapital"><input type="radio" value="6.70"
name="valFrete" />R$ 6,70</div>
<div id="normal-mgprrjscInterior"><input type="radio" value="7.20"
name="valFrete" />R$ 7,20</div>
<div id="sedex-mgprrjscCapital"><input type="radio" value="12.60"
name="valFrete" />R$ 12,60</div>
<div id="sedex-mgprrjscInterior"><input type="radio" value="18.60"
name="valFrete" />R$ 18,60</div>
<div id="valor">R$<span id="valorOnlyNumber"> 210.00</span></div>
+++++++++++++++++++++
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
More information about the Javascript
mailing list