R
Randi
Hi is there any other way of writing this function, I am just wondering if
there is another way of reading through the array like using a for loop or
something. Can you do this using a for loop?
Thanks
var base = 799;
var RAM = [ 0, 70, 150, 280 ];
var HD = [ 0, 30, 70 ];
var OS = [ 0, 70, 20, 90 ];
function calcPrice() {
var price = base;
var form = document.forms[ 'myForm' ];
price += RAM[ form.elements[ 'RAM' ].selectedIndex ];
price += HD[ form.elements[ 'HardDrive' ].selectedIndex ];
price += OS[ form.elements[ 'OS' ].selectedIndex ];
alert(myForm.customerName.value+ " your new computer costs "+"$"+price +
".00");
}
<-- this is my entire code for this program.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Harmon's Computer Store</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>
<script language="JavaScript">
var base = 799;
var RAM = [ 0, 70, 150, 280 ];
var HD = [ 0, 30, 70 ];
var OS = [ 0, 70, 20, 90 ];
function Calc(){
if (myForm.customerName.value != ""){
calcPrice();
}
else{
alert("Enter your name");
}
}
function calcPrice() {
var price = base;
var form = document.forms[ 'myForm' ];
price += RAM[ form.elements[ 'RAM' ].selectedIndex ];
price += HD[ form.elements[ 'HardDrive' ].selectedIndex ];
price += OS[ form.elements[ 'OS' ].selectedIndex ];
alert(myForm.customerName.value+ " your new computer costs "+"$"+price +
".00");
}
</script>
</head>
<body>
<p align="center"><font color="#FF0000" size="+2" face="Arial, Helvetica,
sans-serif">Harmon's Computer Store</font></p>
<table width="75%" border="0">
<tr>
<td width="35%"><div align="center"><img src="CSC%202410/images.jpg"
width="103" height="90"></div></td>
<td width="65%">The base price of this computer is $799. Because this is
a spring break
special, the manufacturer offers limited options.</td>
</tr>
</table>
<p> </p>
<p>Intel Pentium 4 300 GHz , 128 MB RAM, 40 G Hard Drive, 48x/24x/48 CD RW,
17"
color monitor.</p>
<form name="myForm" method="post" onSubmit="Calc(myForm)">
<p>Optional Upgrades</p>
<p>
RAM:<br>
<select name="RAM">
<option>128 MB</option>
<option>256 MB DDR(add $70)</option>
<option>512 MB DDR (add $150)</option>
<option>1 GM DDR (add $280)</option>
</select>
</p>
<p>
Hard Drive:<br>
<select name="HardDrive">
<option> 40 GB</option>
<option>80 GB (add $30)</option>
<option>120 GB (add $70) </option>
</select>
</p>
<p>
Operating System:<br>
<select name="OS">
<option>Windows XP Home Edition</option>
<option>Windows XP Professional Edition (add $70)</option>
<option>Windows XP Home Edition with Microsoft Plus (add $20)</option>
<option>Windows XP Home Professional Edition with Microsoft Plus (add
$90)</option>
</select>
</p>
<p>Enter your name here:
<input type="text" name="customerName">
</p>
<p>
<input type="submit" name="Submit" value="Price" >
</p>
<p> </p>
</form>
<p> </p>
</body>
<script language="JavaScript">
<!--
window.open = SymRealWinOpen;
//-->
</script>
</html>
there is another way of reading through the array like using a for loop or
something. Can you do this using a for loop?
Thanks
var base = 799;
var RAM = [ 0, 70, 150, 280 ];
var HD = [ 0, 30, 70 ];
var OS = [ 0, 70, 20, 90 ];
function calcPrice() {
var price = base;
var form = document.forms[ 'myForm' ];
price += RAM[ form.elements[ 'RAM' ].selectedIndex ];
price += HD[ form.elements[ 'HardDrive' ].selectedIndex ];
price += OS[ form.elements[ 'OS' ].selectedIndex ];
alert(myForm.customerName.value+ " your new computer costs "+"$"+price +
".00");
}
<-- this is my entire code for this program.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Harmon's Computer Store</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>
<script language="JavaScript">
var base = 799;
var RAM = [ 0, 70, 150, 280 ];
var HD = [ 0, 30, 70 ];
var OS = [ 0, 70, 20, 90 ];
function Calc(){
if (myForm.customerName.value != ""){
calcPrice();
}
else{
alert("Enter your name");
}
}
function calcPrice() {
var price = base;
var form = document.forms[ 'myForm' ];
price += RAM[ form.elements[ 'RAM' ].selectedIndex ];
price += HD[ form.elements[ 'HardDrive' ].selectedIndex ];
price += OS[ form.elements[ 'OS' ].selectedIndex ];
alert(myForm.customerName.value+ " your new computer costs "+"$"+price +
".00");
}
</script>
</head>
<body>
<p align="center"><font color="#FF0000" size="+2" face="Arial, Helvetica,
sans-serif">Harmon's Computer Store</font></p>
<table width="75%" border="0">
<tr>
<td width="35%"><div align="center"><img src="CSC%202410/images.jpg"
width="103" height="90"></div></td>
<td width="65%">The base price of this computer is $799. Because this is
a spring break
special, the manufacturer offers limited options.</td>
</tr>
</table>
<p> </p>
<p>Intel Pentium 4 300 GHz , 128 MB RAM, 40 G Hard Drive, 48x/24x/48 CD RW,
17"
color monitor.</p>
<form name="myForm" method="post" onSubmit="Calc(myForm)">
<p>Optional Upgrades</p>
<p>
RAM:<br>
<select name="RAM">
<option>128 MB</option>
<option>256 MB DDR(add $70)</option>
<option>512 MB DDR (add $150)</option>
<option>1 GM DDR (add $280)</option>
</select>
</p>
<p>
Hard Drive:<br>
<select name="HardDrive">
<option> 40 GB</option>
<option>80 GB (add $30)</option>
<option>120 GB (add $70) </option>
</select>
</p>
<p>
Operating System:<br>
<select name="OS">
<option>Windows XP Home Edition</option>
<option>Windows XP Professional Edition (add $70)</option>
<option>Windows XP Home Edition with Microsoft Plus (add $20)</option>
<option>Windows XP Home Professional Edition with Microsoft Plus (add
$90)</option>
</select>
</p>
<p>Enter your name here:
<input type="text" name="customerName">
</p>
<p>
<input type="submit" name="Submit" value="Price" >
</p>
<p> </p>
</form>
<p> </p>
</body>
<script language="JavaScript">
<!--
window.open = SymRealWinOpen;
//-->
</script>
</html>