473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Array - for loop

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>&nbsp;</p>
<p>Intel Pentium 4 300 GHz , 128 MB RAM, 40 G Hard Drive, 48x/24x/48 CD RW,
17&quot;
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>&nbsp;</p>
</form>
<p>&nbsp;</p>
</body>

<script language="JavaScript">
<!--

window.open = SymRealWinOpen;

//-->
</script>

</html>


Jul 23 '05 #1
1 1596
On Thu, 08 Apr 2004 17:05:36 GMT, Randi <RS******@stny.rr.com> wrote:
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?


[snip]

And what array would that be. I see three, four if you include the forms
collection, and no need to loop through any of them.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not...
11
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I've noticed a few threads (full of sound and fury, signifying nothing) here recently about allocation of large memory blocks. I'm about to start on a personal pet project where I'll be using...
1
by: Sluggoman | last post by:
Hi all, Am floundering through a course in which C was not a pre-req, but the assignment is in C - If someone could point out where I am going way off the rails, I'd apprecciate it. Please be...
4
by: frizzle | last post by:
Hi there, I have a function to create an array of all files in a certain folder, so i can display the structure. The actual function is below the message, as is an example of its output. As...
6
by: lukasso | last post by:
Hi, this is my code that should produce something like a timetable for a few days with each day divided into 30 minute pieces. It makes query from MySQL and then creates a 2d $array which then is to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.