Forum Moderators: open

Message Too Old, No Replies

Simple Update

         

iamrick

1:04 pm on Mar 4, 2004 (gmt 0)

10+ Year Member



I'm trying to get a simple shopping cart feature of a real-time update of a price using javascript (or anything else) when the user selects various form options that are avaliable. Here's an example of the code:

<form name="form1" method="post" action="">
<strong>Price</strong> US$24.95<strong><br>
Shipping</strong>
<select name="select2">
<option selected>Priority</option>
<option>Surface</option>
</select>
<strong><br>
Quantity</strong>
<select name="select4">
<option>0</option>
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
</form>

Basically the following price structure exists:

Shipping:
1.) Priority = Add $10
2.) Surface = Add $5

Quantity
The item costs $24.95 each

How can I make it so when the user clicks on the forms, the price above it is updated?

Cheers,

Rick.

korkus2000

1:40 pm on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would do this server side since there is no gaurantee that the user will have js available. This seems to be a mission critical situation and you should really handle it server side.

PatomaS

5:38 pm on Mar 5, 2004 (gmt 0)

10+ Year Member



Hello

:)

In deed is very strange that a user have js disabled, so i think this example is a nice begining for your situation...

<script language="JavaScript" type="text/javascript">
function change() {
var b = new Number(document.forms[0].elements[1].value)
document.forms[0].elements[0].value = 24 + b;

}
</script>

...

<form name="form1" method="post" action="" id="form1">
<input type="text" value="" id="value">
<strong>Price</strong> US$24.95<strong><br>
Shipping</strong>
<select name="select2" onchange="javascript:algo()">
<option selected value="10">Priority</option>
<option value="5">Surface</option>
</select>
<strong><br>Quantity</strong>
<select name="select4">
<option>0</option>
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
</form>

Just have to add values in the options

Hope it helps

Bye