Click to See Complete Forum and Search --> : Update Totals on Same Page


javascriptHelp
10-12-2003, 10:02 AM
Can someone please help me. I'm trying to update subtotals with a quantity drop down box. I want the subtotal to update when the user clicks a update button. Don't know where to start!

Khalid Ali
10-12-2003, 10:21 AM
Originally posted by javascriptHelp
Don't know where to start!

interestingly enough ..we don't either,since you did not provide any code/link to take a look at...

javascriptHelp
10-12-2003, 10:40 AM
Here is the code I have so far

Khalid Ali
10-12-2003, 10:43 AM
there is not html in it....

javascriptHelp
10-12-2003, 10:49 AM
All the code for the page!

Thanks

Khalid Ali
10-12-2003, 10:55 AM
Listen my friend.run the script from your webserver and then copy the complete created html and post that.....

javascriptHelp
10-12-2003, 10:58 AM
Sorry, Very New as JS

Khalid Ali
10-12-2003, 11:20 AM
this should take care of it,however there is allots that needs to be done in this program..


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
var price =39.95;//you will need to create some method to dynamically set prices for different items
function Cancel()
{
document.frmCustOrderInfo.action = "cancelOrder.asp";
document.frmConfirmCustInfo.submit();
}


function UpdateTotals(){
if (document.frmCustOrderInfo.country.value == "Canada"){
var listbox = document.frmCustOrderInfo.quantityAmount;
quantity = parseInt(listbox.options[listbox.selectedIndex].value);
subtotal = (quantity * price).toFixed(2);
document.frmCustOrderInfo.txtPrice.value = subtotal
}
}

-->
</script>
</head>

<body>
<form name="frmCustOrderInfo" method="post" action="">
<div align="center">
<p><img src="images/handybar_image.jpg" width="300" height="158"> </p>
<p>Customer Order Information</p>
Country : <input type="text" name="country" value="Canada"/>
<table width="75%" border="0">
<tr>
<td width="12%">Quantity</td>
<td width="31%">
<select name="quantityAmount" default="None">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select>&nbsp;<b>*</b>&nbsp; 39.95</td>
<td width="26%">Subtotal </td>
<td width="31%"><input name="txtPrice" type="text" id="txtPrice" size="10" readonly="readonly"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Shipping and Handling </td>
<td width="31%"><input name="txtShipHand" type="text" size="10" value=3.95> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Taxes:</td>
<td width="31%"><input name="txtTaxes" type="text" size="10" value=10.00></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Total:</td>
<td></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Button" type="button" onclick="UpdateTotals();" value="Update Totals"></td>
<td><input type="submit" name="Submit2" value="Continue" onclick="Continue();"></td>
<td><input type="submit" name="Submit3" value="Cancel" onClick="Cancel();"></td>
</tr>
</table>
</div>
</form>
<p>&nbsp;</p>
<p>&nbsp; </p>
</body>
</html>

javascriptHelp
10-12-2003, 11:29 AM
Thanks so Much. It doesn't work with the if statement though. If I comment out the If statement, it works fine. Not sure why!

Khalid Ali
10-12-2003, 12:46 PM
you are welcome..
for the if statement you will have to see what it does,
it looks for a field in the form where value=="Canada" and if this condition matches then it goes in the if block.