LuigiX
11-12-2003, 09:34 PM
Hi
I have 2 combo boxes which provide a subtotal which formats the answer as currency. This works ok but the grandtotal will not add when the convertcurrency function is called.
Code below
Cheers
Luigi
<html>
<head>
<meta http-equiv="Content-Language" content="en-nz">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 6</title>
<script type="text/javascript">
<!-- Begin
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
// End -->
function updatesum() {
document.form.sum.value = formatCurrency((document.form.s1.options[document.form.s1.selectedIndex].text-0) * 10)
document.form.sum1.value = formatCurrency((document.form.s3.options[document.form.s3.selectedIndex].text-0) * 15)
document.form.total.value = formatCurrency(document.form.sum.value) + formatCurrency(document.form.sum1.value)
}
//--></script>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--" name="form">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="300" id="AutoNumber1">
<tr>
<td>computer</td>
<td><select size="1" name="s1" onChange="updatesum()">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select></td>
<td><input type="text" name="sum" size="20"></td>
</tr>
<tr>
<td>phone</td>
<td><select size="1" name="s3" onChange="updatesum()">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select></td>
<td><input type="text" name="sum1" size="20"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="text" name="total" size="20"></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
I have 2 combo boxes which provide a subtotal which formats the answer as currency. This works ok but the grandtotal will not add when the convertcurrency function is called.
Code below
Cheers
Luigi
<html>
<head>
<meta http-equiv="Content-Language" content="en-nz">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 6</title>
<script type="text/javascript">
<!-- Begin
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
// End -->
function updatesum() {
document.form.sum.value = formatCurrency((document.form.s1.options[document.form.s1.selectedIndex].text-0) * 10)
document.form.sum1.value = formatCurrency((document.form.s3.options[document.form.s3.selectedIndex].text-0) * 15)
document.form.total.value = formatCurrency(document.form.sum.value) + formatCurrency(document.form.sum1.value)
}
//--></script>
</head>
<body>
<form method="POST" action="--WEBBOT-SELF--" name="form">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="300" id="AutoNumber1">
<tr>
<td>computer</td>
<td><select size="1" name="s1" onChange="updatesum()">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select></td>
<td><input type="text" name="sum" size="20"></td>
</tr>
<tr>
<td>phone</td>
<td><select size="1" name="s3" onChange="updatesum()">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select></td>
<td><input type="text" name="sum1" size="20"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="text" name="total" size="20"></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>