473,799 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with shopping cart problem

Hi, Thanks David and I got that to work, I guess I still need to get it to
work using the arrays and the selectedIndex property. I have to use an
alert box that shows the total price like: The cost = the base price + RAM
price + Hard Drive Price + Operating System Price The cost = the base price
+ RAM price + Hard Drive Price + Operating System Price. This is what I
have so far, I think i need to use a for loop, because of the array. Any
help would be appreciated. The code I have so far is
below.

Thanks,

Randi

<!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="JavaS cript">
var basePrice = 799;

var Ram = new Array(0, 70, 150, 280);
var HD = new Array(0, 30, 70);
var OS = new Array(0, 70, 150, 280);

function Calc(myForm){

}

</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%"><di v align="center"> <img src="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>
<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>
<select name="HardDrive ">
<option> 40 GB</option>
<option>80 GB (add $30)</option>
<option>120 GB (add $70) </option>
</select>
</p>
<p>
<select name="OS">
<option>Windo ws XP Home Edition</option>
<option>Windo ws XP Professional Edition (add $70)</option>
<option>Windo ws XP Home Edition with Microsoft Plus (add $20)</option>
<option>Windo ws XP Home Professional Edition with Microsoft Plus (add
$90)</option>
</select>
</p>
<p>Enter your name here:
<input type="text" name="customerN ame">
</p>
<p>
<input type="submit" name="Submit" value="Price">
</p>
<p>&nbsp;</p>
</form>
<p>&nbsp;</p>
</body>
</html>
Jul 23 '05 #1
1 1310
On Sat, 03 Apr 2004 13:32:58 GMT, Randi <RS******@stny. rr.com> wrote:
Hi, Thanks David and I got that to work,
Good...
I guess I still need to get it to work using the arrays and the
selectedIndex property.
....so I don't see why you're trying to pursue another course of action.
I have to use an alert box
Why? Do you have something against people that don't use JavaScript?

All of this would be best performed on a server anyway, using a
centralised database and guaranteed execution. Using JavaScript means
updating multiple pages if you alter prices (which you are sure to do when
selling computer equipment), and needlessly excluding potential customers
that don't use JavaScript.
that shows the total price like: The cost = the base price + RAM price
+ Hard Drive Price + Operating System Price [snipped 2nd instance]
So you just duplicate what David suggested for the other price modifiers.
This is what I have so far, I think i need to use a for loop, because of
the array.


As you don't need the array, you don't need the loop. However, this is how
you could do it:

var base = 799;
var RAM = [ 0, 70, 150, 280 ];
var HD = [ 0, 30, 70 ];
var OS = [ 0, 70, 150, 280 ];

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 ];

// "price" now contains the modified total
}

[snipped code]

From your original post:

<form name="myForm" method="post" onSubmit="Calc( myForm)">

This won't work on a lot of browsers. Only a few browsers allow you to use
id and name attribute values as references to the respective elements. Use
either the well supported collections (forms, images, etc) or DOM methods
to access elements. However, in this case, you simply need to use

<form ... onsubmit="Calc( this)">

which will pass a reference to the form to the Calc() function.

Mike

--
Michael Winter
M.******@blueyo nder.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

3
3272
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old scripts working on a new server with the most recent version of PHP. I've pretty much taken care of all the various errors that were popping up. Most only pointed out out non-fatal undefined or assumed variables. I've been able to cure most of...
2
2869
by: Don Grover | last post by:
I am retrieving costs and product id's from a sql db. and need to build a shopping cart around it. How do I store the selected items and qty req so I can move into another catalog and total up as im going. Just a couple of hints will do, Im familiar with vb script but not java based code , and im wondering how to store what they select so I can move around different product ranges. Don
1
3583
by: madison | last post by:
Hi, I am trying to start a website using paypals shopping cart function. If i have 10 items and they sell out, how do I make it so the item is then listed as sold out. The next person would not be able to come along and add it to their shopping cart. thanks joy
1
1823
by: Jia Sun | last post by:
hello , everybody , i need a similar program , just like fancyimport.com if possible, pls contact me ,thank you very much . inchina@gmail.com
1
3231
by: Adil Akram | last post by:
I have created a site shopping cart in ASP.net. I am using ASP session object's SessionID on non SSL connection to track session. While adding products to cart DB I insert product and SessionID in table. All products and cart status pages are on non SSL connection. On checkout to get secure user information I shifted connection to SSL but when shifting to SSL, the SessionID changed (As is this is default behavior of IIS to prevent...
2
2301
by: G.E.M.P | last post by:
High Level Session Handling Design for a Shopping cart 0) What am I missing? 1) How does OSCommerce do it? I'm thinking about building a shopping cart from scratch, using a library of dynamic screen generation routines (already written) that take an XML stream as input from various "search for products" forms. That way I can run queries in one window and display the dynamic results in another. The searching functions will probably
7
2637
by: isaac2004 | last post by:
hi i have a basic asp page that acts as an online bookstore. on my cart page i am having trouble generating 3 numbers; a subtotal, a shipping total, and a final price. here is my code i would like it to work properly so that a record count counts through all the books and genertates these numbers. watch out for line breaks <%@ Language=VBScript %> <% Option Explicit %> <!--#include file="DatabaseConnect.asp"-->
2
2322
by: isaac2004 | last post by:
hi i am creating a basic asp site that uses cookies to manage a cart for an online store. whenever i open this page without adding anything to the cart. i get an error message. here is my code <%@ Language=VBScript %> <% Option Explicit %> <!--#include file="DatabaseConnect.asp"--> <!--#include virtual="06winter/levini/database/adovbs.inc"-->
3
1550
by: isaac2004 | last post by:
hello i am making a spoof online book store site for a class and I was wondering how i could fix a problem i am having. I have two tables, one the cart and the other a table with book descriptions. what i am trying to do is display the book info for the cart through a SQL statement. the only problem is when i do this it just outputs the info for all books in the database. how would i change my SQL statement to only read the info for the...
0
3698
by: samjam | last post by:
Below is some coding in a program i am using, i would like to know how i can get the text bigger or bolder on my webpage, This is the section of text i would like bigger or bolder (This is a very rare lacquered tea caddy c1840. The outside of the caddy has wonderful scenes on each side which are really finely painted. The caddy stands on claw feet. Inside there are four tin canister which is very rare to see on such a small caddy. All canisters...
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7571
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.