HighDots Forums  

Re: Help with shopping cart problem

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Help with shopping cart problem in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Winter
 
Posts: n/a

Default Re: Help with shopping cart problem - 04-03-2004 , 04:30 PM






On Sat, 03 Apr 2004 13:32:58 GMT, Randi <RSaddler (AT) stny (DOT) rr.com> wrote:

Quote:
Hi, Thanks David and I got that to work,
Good...

Quote:
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.

Quote:
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.

Quote:
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.

Quote:
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.Winter (AT) blueyonder (DOT) co.invalid (replace ".invalid" with ".uk" to reply)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.