I have an order form based on javascript
fairly simple: type in # of books
select a radio box for type of shipping,
values are displayed in non-editable form fields
everything shows up correctly on page, yet when the submit button is pressed the shipping cost is added in twice?
I’ve played with this script for hours, and have something simple eluding me why this is going on…
any help is greatly appreciated
The function:
[CODE]<script language=”javascript”>
<!– Begin
function shop(f) {
f.amount.value = (subtot + (f.books.value * ship)) / 100;
var subt = Number(f.books.value) * 15.95;
var subtot = Math.round(subt * 100)
f.subtotal.value = subtot / 100;
if (f.shipbut[0].checked) {
var ship = 4;
} else if (f.shipbut[1].checked) {
var ship = 6;
} else if (f.shipbut[2].checked) {
var ship = 8;
}
f.shipping.value = Number(f.books.value * ship);
f.amount.value = Number(f.books.value * 15.95) + Number(f.books.value * ship);
}
// End –>
</script>
The Form (Can’t get it to show up in code brackets):
<form action=”” method=”post”>
<input type=”hidden” name=”cmd” value=”VALUES FOR PAYPAL” />
<table width=”540″ cellpadding=”5″ cellspacing=”0″>
<tr>
<td>Benefits of Marijuana</td>
<td colspan=”2″ align=”right”>Number of copies ($15.95 each)
<input name=”books” onchange=”shop(this.form)” onfocus=”select()” type=”text” id=”books” value=”1″ size=”4″ /></td>
</tr>
<tr>
<td>Subtotal</td>
<td colspan=”2″ align=”right”>$
<input name=”subtotal” type=”text” id=”subtotal” readonly=”readonly” value=”15.95″ size=”8″ /></td>
</tr>
<tr>
<td>Shipping</td>
<td align=”right”>
<label>Standard shipping (US) <input type=”radio” name=”shipbut” value=”4″ id=”shipping_0″ onchange=”shop(this.form)” checked=”checked” /></label><br />
<label>Priority shipping (US) <input type=”radio” name=”shipbut” value=”6″ id=”shipping_1″ onchange=”shop(this.form)” /></label><br />
<label>Priority shipping outside the US <input type=”radio” name=”shipbut” value=”8″ id=”shipping_2″ onchange=”shop(this.form)” /></label>
</td>
<td align=”right”>$
<input name=”shipping” type=”text” id=”shipping” readonly=”readonly” value=”4.00″ size=”8″ /></td>
</tr>
<tr>
<td>Total</td>
<td colspan=”2″ align=”right”>$
<input name=”amount” type=”text” id=”amount” readonly=”readonly” value=”19.95″ size=”8″ /></td>
</tr>
<tr align=”center”>
<td colspan=”3″><input name=”submit” type=”submit” value=”Click here to Purchase” onchange=”shop(this.form)” /></td>
</tr>
</table>
</form>