Dynamically total textbox and checkbox

B

bird

Greetings,

I'm trying to calculate the total on an php page. I'm able to get the
checkbox portion to work properly but I'm having trouble with the
textbox "txtshipping". The default is 7.95 but if changes I need to
change the total.

How can I make the totalbox the default of the textbox of
"txtshipping"?

I struggle with javascript so any help would be greatly appreciate.

Thanks in advance.
Bird

<script type="text/javascript">

function gettotal(){

var tmp = 0;
var nBox = document.getElementsByName('chkboxpackage[]');
for(i=1; i<nBox.length+1; i++)
{
if (nBox[i-1].checked)
{
tmp += parseFloat(document.forms[0]['hdnPackage'+i].value);

}
}

var nBox2 = document.getElementsByName('chkboxitem[]');
for(i=1; i<nBox2.length+1; i++)
{
if (nBox2[i-1].checked)
{
tmp += parseFloat(document.forms[0]['hdnItem'+i].value);

}
}

tmp += parseFloat(document.forms[0]['txtshipping'].value);


document.forms[0].totalbox.value = tmp.toFixed(2);
}

</script>

<input type="checkbox" name="chkboxpackage[]" value="1"
onClick="gettotal()">
<input type="hidden" name="hdnPackage1"
value="69.95" >

<input type="checkbox" name="chkboxpackage[]" value="2"
onClick="gettotal()">
<input type="hidden" name="hdnPackage2"
value="49.95" >
<input type="checkbox" name="chkboxpackage[]" value="3"
onClick="gettotal()">
<input type="hidden" name="hdnPackage3"
value="495.00" >
<input type="checkbox" name="chkboxitem[]" value="1"
onClick="gettotal()">
<input type="hidden" name="hdnItem1"
value="89.95" >
<input type="checkbox" name="chkboxitem[]" value="2"
onClick="gettotal()">
<input type="hidden" name="hdnItem2"
value="99.95" >
<input type="checkbox" name="chkboxitem[]" value="3"
onClick="gettotal()">
<input type="hidden" name="hdnItem3"
value="149.95" >


<input name="txtShipping" type="text" size="15"
onChange="gettotal()"></td>
<input type="text" name="totalbox"
value="0.00" readonly/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top