...

View Full Version : Please Help Me



signman
12-26-2010, 07:46 PM
I have this code, but when I get to the last package, it returns a value of 0

I really can't understand what I am doing wrong. Please help me if you can. I aim to add another 4 categories to this calculator.


<html>
<head></head>
<body>
<form name=theForm onclick=getTotal() >
<div class="item">
<h1>Wedding Package:</h1>
</div>
<input name="WP" type="radio" checked value="399~~Package1"> Package 1 <br>
<input name="WP" type="radio" checked value="499~~Package2"> Package 2 <br>
<input name="WP" type="radio" checked value="599~~Package3"> Package 3 <br>
<input name="WP" type="radio" checked value="699~~Package4"> Package 4 <br>
<input name="WP" type="radio" checked value="799~~Package5"> Package 5 <br>
<input name="WP" type="radio" checked value="899~~Package6"> Package 6 <br>
<input name="WP" type="radio" checked value="999~~Package7"> Package 7 <br>
<input name="WP" type="radio" checked value="1000~~Package8"> Package 8 <br>
<br><br>

</form>

<span id=totalspan>
</span>
</body>

<script type=text/javascript>
function getTotal(){
var form=document.theForm;
var inputs=form.getElementsByTagName('input');
var length=inputs.length;
var total='0';

for(i=0;i<length-1;i++){
if(inputs[i].type=='radio'){
var checked=inputs[i].checked?1:0;
if(checked){
var value=inputs[i].value.split("~~")[0];
total-=-value;
}
}
}
document.getElementById('totalspan').innerHTML="<strong>Total price will be: </strong>"+total
}

</script>


</html>

DJCMBear
12-26-2010, 08:33 PM
Change this.
total-=-value;
To this.
total = value[0];

And also change the onclick on the form tag to onsubmit and add a submit button or add the onclick to each of the radio buttons.

signman
12-26-2010, 10:05 PM
Thank you so much



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum