...

View Full Version : checkboxes & ff



moiseszaragoza
08-27-2009, 04:30 PM
have a simple calculator i made with checkboxes and some Js.

the problem is that it does not work in FF.

any idea how this can work for
IE
Safari
AND FF





function getPrice(amount, boxName){
total = eval() ;

checked = document.getElementById(boxName).checked
if (checked){
total = parseFloat(form1.Total2.value) + parseFloat(amount);

}else{
total = parseFloat(form1.Total2.value) - parseFloat(amount);

}
total.toFixed(2);
form1.Total2.value = total
document.getElementById("total").innerHTML = "Total $"+total;
}

Amphiluke
08-27-2009, 04:59 PM
FF expects from you use the getElementById method instead of direct referring by the name of a form.

<script type="text/javascript">
function getPrice(amount, boxName){
var checked = document.getElementById(boxName).checked;
var form1 = document.getElementById("form_1")
if (checked){
total = parseFloat(form1.Total2.value) + parseFloat(amount);
} else {
total = parseFloat(form1.Total2.value) - parseFloat(amount);
}
form1.Total2.value = total.toFixed(2);
document.getElementById("total").innerHTML = "Total $"+total.toFixed(2);
}
</script>

<form action="#" name="form_1" id="form_1">
<input type="checkbox" name="box" id="box" value="box" /> I am a checkbox<br />
Total: <input type="text" name="Total2" /><br />
Amount: <input type="text" name="Amount" />
<div id="total">&nbsp;</div>
<input type="button" value="get price" onclick="getPrice(this.form.Amount.value, 'box');" />
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum