/    Sign up×
Community /Pin to ProfileBookmark

Simple problem – solution eluding me…

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>
[/CODE]

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>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Nov 12.2007 — [code=html]<input name="submit" type="submit" value="Click here to Purchase" onchange="shop(this.form)" />[/code]
?

Try instead:
[code=html]
<form onsubmit="shop(this.form);return true;">etc.</form>
[/code]
Copy linkTweet thisAlerts:
@amitesauthorNov 13.2007 — I appreciate the idea, same result

if I select a different shipping method, or change the quantity then the shipping is added twice,

I can tell this is something staring me in the face, it's just too elusive
×

Success!

Help @amites spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...