/    Sign up×
Community /Pin to ProfileBookmark

Trying to create simple order form.

I need Javascript help with my order form, which I’ve created in Dreamweaver. The customer must indicate their desired quantity of my product. The form must add tax depending on what province they live in, and produce a total. I can look these tax figures up, but how would I set up a drop-down menu for customers to indicate province, and javascript to alter the tax percentage accordingly?

I’m trying to get a handle on javascript, but programming is new to me. Can anyone point me towards an example of such a script?

Ken

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorAug 22.2005 — what have you done so far?
Copy linkTweet thisAlerts:
@Ken_RogersauthorAug 23.2005 — This is the "meat and potatoes" of my form. "function doMath" is a mess. All I'm trying to do here is create a simple form that applies the applicable percentage of sales tax, depending on your province. Any advice would be helpful.

[URL=http://www.preciouseffects.com/salestaxform.html]See my troubled form[/URL]

<html>

<head>

<script language="JavaScript" type="text/JavaScript">

<!--


function doMath() {

var quant = eval(document.myform.quantity.value)

var pric = eval(document.myform.price.value)

var getsubto = quant * pric

var pstrate = eval(document.myform.state.value)

var getpst = quant *
price * pstrate

var gstrate = .07

var getgst = quant *
price * gstrate

var addup = getsubto + getpst + getgst + 4.95

document.myform.subtotal.value=custRound(getsubto,2);

document.myform.pst.value=custRound(getpst,2);

document.myform.gst.value=custRound(getgst,2);

document.myform.Payment_Amount.value=custRound(addup,2);

}

function custRound(x,places) {

return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)

}

//-->

</script>

</head>

<body>

<center>

<form method="POST" action="" FORM NAME="myform">

<select name="state">

<option value="0.00">Alberta</option>

<option value="0.07">British Columbia</option>

<option value="0.07">Manitoba</option>

<option value="0.00">New Brunswick</option>

<option value="0.00">Newfoundland</option>

<option value="0.00">Labrador</option>

<option value="0.00">Northwest Territories</option>

<option value="0.00">Nova Scotia</option>

<option value="0.00">Nunavut</option>

<option value="0.08">Ontario</option>

<option value="0.10">PEI</option>

<option value="0.075">Quebec</option>

<option value="0.07">Saskatchewan</option>

<option value="0.00">Yukon Territories</option>

</select>

<TABLE BORDER="0" width="490">

<TR>

<Td width="124"><div align="left"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>Item</strong></font></div></Td>

<Td width="75"><div align="center"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>Quantity</strong></font></div></Td>

<Td><div align="center"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>Price</strong></font></div></Td>

<Td><div align="center"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>Total</strong></font></div></Td>

</TR>

<TR>

<TD height="24"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">AirNav

VFR V2.4</font></TD>

<TD valign="middle"> <div align="center">

<input name="quantity" type="text" id="quantity" value="1" size="5">

</div></TD>

<TD valign="middle"><div align="center"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">

<input name="price" type="text" id="price" value="$99.95" size="10">

<font size="2">(Reg $150)</font></font></div></TD>

<TD><div align="center"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">

<INPUT NAME="subtotal" TYPE="text" id="Payment_Amount2" VALUE="99.95" SIZE="15">

</font></div></TD>

</TR>

<TR>

<TD height="24">PST</TD>

<TD valign="middle">&nbsp;</TD>

<TD valign="middle">&nbsp;</TD>

<TD><div align="center">

<input name="pst" type="text" id="pst" size="15">

</div></TD>

</TR>

<TR>

<TD height="24">GST</TD>

<TD valign="middle">&nbsp;</TD>

<TD valign="middle">&nbsp;</TD>

<TD><div align="center">

<input name="gst" type="text" id="gst" size="15">

</div></TD>

</TR>

<TR>

<TD height="24">HST</TD>

<TD valign="middle">&nbsp;</TD>

<TD valign="middle">&nbsp;</TD>

<TD><div align="center">

<input name="hst" type="text" id="hst" size="15">

</div></TD>

</TR>

<TR>

<TD height="31">Shipping</TD>

<TD valign="middle">&nbsp;</TD>

<TD valign="middle">&nbsp;</TD>

<TD><div align="center">

<input name="shipping" type="text" id="shipping" value="4.95" size="15">

</div></TD>

</TR>

<TR>

<TD height="84" valign="top">Grand Total</TD>

<TD valign="middle"><div align="center"></div></TD>

<TD WIDTH="173" valign="middle"><p align="center"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">

<BR>

</font></p></TD>

<TD WIDTH="100" valign="top"><div align="center">

<p><font size="3" face="Verdana, Arial, Helvetica, sans-serif">

<input name="Payment_Amount" type="text" id="Payment_Amount" size="15">

</font></p>

<p><font size="3" face="Verdana, Arial, Helvetica, sans-serif">

<input type="button" value="Calculate" onClick="doMath()" name="button">

</font></p>

</div></TD>

</TR>

</table>

<br> <br> </td>

</tr>


</FORM>

</body>

</html>
×

Success!

Help @Ken_Rogers 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 5.21,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...