-
Javascript Calculate
i have a problem with my code, and i cannot find it
can someone please read over my code, because ive tried fixing it 3 times now and i cant find anymore wrong with it
Code:
<!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">
function doCalc(){
cost1.tcost1.value = Math.round(eval(quant1.amt1.value * size1.prsize1.value)*100)/100
cost2.tcost2.value = Math.round(eval(quant2.amt2.value * size2.prsize2.value)*100)/100
cost3.tcost3.value = Math.round(eval(quant3.amt3.value * size3.prsize3.value)*100)/100
cost4.tcost4.value = Math.round(eval(quant4.amt4.value * size4.prsize4.value)*100)/100
cost5.tcost5.value = Math.round(eval(quant5.amt5.value * size5.prsize5.value)*100)/100
cost6.tcost6.value = Math.round(eval(quant6.amt6.value * size6.prsize6.value)*100)/100
t = Math.round(eval(size1.prsize1.vlaue + '+' + size2.prsize2.vlaue + '+' + size3.prsize3.vlaue + '+' + size4.prsize4.vlaue + '+' + size5.prsize5.vlaue + '+' + size6.prsize6.vlaue)*100)100)
totalcost.totalcst.value = '$' + t.toFixed(2)
}
</script>
</head>
<body>
<table width="379" border="0" align="center">
<tr>
<td width="84"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Product</font></td>
<td width="64"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Quantity</font></td>
<td width="75"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Size</font></td>
<td width="44"> </td>
<td width="90"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Cost</font></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Product1</font></td>
<td><form action="" name="quant1">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="amnt1" type="text" value="0" size="10" maxlength="10">
</font></form></td>
<td><form name="size1">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<select name="prsize1" size="1">
<option value=".50" selected>Small</option>
<option value=".85">Medium</option>
<option value="1.50">Large</option>
</select>
</font></form></td>
<td> </td>
<td><form name="cost1">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="tcost1" type="text" value="0" size="15" maxlength="15">
</font></form></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Product2</font></td>
<td><form name="quant2">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="amnt2" type="text" value="0" size="10" maxlength="10">
</font></form></td>
<td><form action="" name="size2">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<select name="prsize2" size="1" id="prsize2">
<option value=".50" selected>Small</option>
<option value=".85">Medium</option>
<option value="1.50">Large</option>
</select>
</font></form></td>
<td> </td>
<td><form name="cost2">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="tcost2" type="text" value="0" size="15" maxlength="15">
</font></form></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Product3</font></td>
<td><form name="quant3">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="amnt3" type="text" value="0" size="10" maxlength="10">
</font></form></td>
<td><form action="" name="size3">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<select name="prsize3" size="1">
<option value=".50" selected>Small</option>
<option value=".85">Medium</option>
<option value="1.50">Large</option>
</select>
</font></form></td>
<td> </td>
<td><form name="cost3">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="tcost3" type="text" value="0" size="15" maxlength="15">
</font></form></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Product4</font></td>
<td><form name="quant4">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="amnt4" type="text" value="0" size="10" maxlength="10">
</font></form></td>
<td><form name="size4">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<select name="prsize4" size="1">
<option value=".50" selected>Small</option>
<option value=".85">Medium</option>
<option value="1.50">Large</option>
</select>
</font></form></td>
<td> </td>
<td><form name="cost4">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="tcost4" type="text" value="0" size="15" maxlength="15">
</font></form></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Product5</font></td>
<td><form name="quant5">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="amnt5" type="text" value="0" size="10" maxlength="10">
</font></form></td>
<td><form name="size5">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<select name="prsize5" size="1">
<option value=".50" selected>Small</option>
<option value=".85">Medium</option>
<option value="1.50">Large</option>
</select>
</font></form></td>
<td> </td>
<td><form name="cost5">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="tcost5" type="text" value="0" size="15" maxlength="15">
</font></form></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Product6</font></td>
<td><form name="quant6">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="amnt6" type="text" value="0" size="10" maxlength="10">
</font></form></td>
<td><form name="size6" id="size6">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<select name="prsize6" size="1" >
<option value=".50" selected>Small</option>
<option value=".85">Medium</option>
<option value="1.50">Large</option>
</select>
</font></form></td>
<td> </td>
<td><form name="cost6">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="tcost6" type="text" value="0" size="15" maxlength="15">
</font></form></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><form name="totalcost" id="totalcost">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="totalcst" type="text" value="0" size="15" maxlength="15">
</font></form></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><form name="calcbutton">
<input type="button" name="calc" value="Calculate" onClick="doCalc()">
</form></td>
</tr>
</table>
</body>
</html>
-
Senior Member
Close bracket where there shouldn't be.
Code:
t = Math.round(eval(size1.prsize1.vlaue + '+' + size2.prsize2.vlaue + '+' + size3.prsize3.vlaue + '+' + size4.prsize4.vlaue + '+' + size5.prsize5.vlaue + '+' + size6.prsize6.vlaue)*100)100)
should be
Code:
t = Math.round(eval(size1.prsize1.vlaue + '+' + size2.prsize2.vlaue + '+' + size3.prsize3.vlaue + '+' + size4.prsize4.vlaue + '+' + size5.prsize5.vlaue + '+' + size6.prsize6.vlaue)*100)100
And I don't know quite enough about javascript...but is it case sensitive?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|