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)