Hello: I am having problem getting an online order form to work. I am using drop down lists for selectable options. Here is the code and keep in mind it's basic until I get it to work. Thanks in advance.
<html>
<head>
<script language = "javascript">
function pricecalculate(){
Var cpu=eval(document.compbuilder.cpu.value);
Var Mboard=eval(document.compbuilder.mboard.value);
document.compbuilder.txtAnswer.value=cpu + mboard;
}
</script>
</head>
<body>
<form name=compbuilder onSubmit="pricecalculate();">
<table>
<tr>
<td>Build a computer</td>
</tr>
<tr>
<td><p>Step 1: Select the CPU:</p></td>
<td> <select name=cpu>
<option value=75>AMD = $75.00
<option value=100>Intel = $100.00
</Select>
</td>
</tr>
<tr>
<td><p>Step 2: Select your Motherboard:</p></td>
<td><select Name=mboard>
<option value=75>Soyo = $75.00
<option value=100>DFI = $100.00
</select>
</td>
</tr>
<tr>
<td><p>Step 3: Click to calculte the price:</p></td>
<td><input type=submit name=calculate value="calculate"></td>
</tr>
<tr>
<td><p>The estimated price of your systems is:</P></td>
<td><input type=text name=txtAnswer></td>
</tr>
</table></form>
</body>
</html>
Brandoe85
11-23-2004, 05:14 AM
Variables begin with var blah, small 'v'. I'm not sure if you want the form to submit when your just displaying their price.
<html>
<head>
<script language = "javascript">
function pricecalculate(){
var cpu=eval(document.compbuilder.cpu.value);
var Mboard = eval(document.compbuilder.mboard.value);
document.compbuilder.txtAnswer.value=cpu + Mboard;
}
</script>
</head>
<body>
<form name=compbuilder action="">
<table>
<tr>
<td>Build a computer</td>
</tr>
<tr>
<td><p>Step 1: Select the CPU:</p></td>
<td> <select name=cpu>
<option value=75>AMD = $75.00
<option value=100>Intel = $100.00
</Select>
</td>
</tr>
<tr>
<td><p>Step 2: Select your Motherboard:</p></td>
<td><select Name=mboard>
<option value=75>Soyo = $75.00
<option value=100>DFI = $100.00
</select>
</td>
</tr>
<tr>
<td><p>Step 3: Click to calculte the price:</p></td>
<td><input type=button name=calculate value="calculate" onClick="pricecalculate();"></td>
</tr>
<tr>
<td><p>The estimated price of your systems is:</P></td>
<td><input type=text name=txtAnswer></td>
</tr>
</table></form>
</body>
</html>
hemebond
11-23-2004, 05:34 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>47873</title>
<style type="text/css">
dt {
float:left;
width:11em;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Build a computer</legend>
<dl>
<dt><label for="cpu">Select the CPU</label></dt>
<dd>
<select id="cpu" name="cpu" onchange="calculate()">
<option value="75">AMD = $75.00</option>
<option value="100">Intel = $100.00</option>
</select>
</dd>
<dt><label for="mboard">Select your Motherboard</label></dt></dt>
<dd>
<select id="mboard" name="mboard" onchange="calculate()">
<option value="75">Soyo = $75.00</option>
<option value="100">DFI = $100.00</option>
</select>
</dd>
</dl>
</fieldset>
</form>
<p>The estimated price of your systems is $<span id="price">uncalculated</span></p>
<script type="text/javascript">
var price = document.getElementById("price").firstChild;
function calculate()
{
var cpu = Number(document.getElementById("cpu").value);
var mboard = Number(document.getElementById("mboard").value);
price.nodeValue = cpu + mboard;
}
calculate();
</script>
</body>
</html>
letenn
11-23-2004, 10:20 PM
Thanks for the replies guys. Could you tell me what I did wrong with the one I did? Or is mine not salvageable? I am trying to learn this stuff so I need to take it slow. Thanks again for the replies..
Brandoe85
11-24-2004, 12:20 AM
I tried to make mine as much like yours as possible.
<html>
<head>
<script language = "javascript">
function pricecalculate(){
-->should be lower case 'v' Var cpu=eval(document.compbuilder.cpu.value);
-->lower case Var Mboard=eval(document.compbuilder.mboard.value);
document.compbuilder.txtAnswer.value=cpu + --> should be same as you declared which was Mboard, mboard;
}
</script>
</head>
<body>
<form name=compbuilder -->no need to submit when your just displaying the cost onSubmit="pricecalculate();">
<table>
<tr>
<td>Build a computer</td>
</tr>
<tr>
<td><p>Step 1: Select the CPU:</p></td>
<td> <select name=cpu>
<option value=75>AMD = $75.00
<option value=100>Intel = $100.00
</Select>
</td>
</tr>
<tr>
<td><p>Step 2: Select your Motherboard:</p></td>
<td><select Name=mboard>
<option value=75>Soyo = $75.00
<option value=100>DFI = $100.00
</select>
</td>
</tr>
<tr>
<td><p>Step 3: Click to calculte the price:</p></td>
<td><input type=-->use button, not submit submit name=calculate value="calculate" use the onClick="pricecalculate();"></td>
</tr>
<tr>
<td><p>The estimated price of your systems is:</P></td>
<td><input type=text name=txtAnswer></td>
</tr>
</table></form>
</body>
</html>