Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    21
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Calculate function doesn't seem to work.

    Hello all, I have a problem with the order form page on my website. I have written a function which I'd hoped would calculate the postage for each order (either domestic or international P+H) but it doesn't seem to work. Am I completely off with the way I've gone about it? Am very much a beginner with JS so I just did it the way I thought best.
    Also I'm after some advice about my submit button. My credit card processor requires me to send the total to them but I still want the order details e-mailed to me. Would it be best if I put an onclick handler on the submit button and then had it execute both a post function to my credit card processor and a mail function to me?
    Any advice is greatly appreciated.
    I've inserted the whole page code below.

    Code:
    <html><head><title>FRC Clothing - Quality casual tees, shirts and caps</title>
    
            
    <script language="JavaScript" script type="text/javascript">
    
    <!--
    
    	var pht = 0;
    
    	function CalculateTotals() {
    		f=document.orderform;
    		f.ssgt.value=parseInt(f.ssg.value)*25;
    		f.ssot.value=parseInt(f.sso.value)*25;
    		f.sswt.value=parseInt(f.ssw.value)*25;
    		f.lsbt.value=parseInt(f.lsb.value)*30;
    		f.lswt.value=parseInt(f.lsw.value)*30;
    		f.tqbwt.value=parseInt(f.tqbw.value)*30;
    		f.tqbgt.value=parseInt(f.tqbg.value)*30;
    		f.tqmgt.value=parseInt(f.tqmg.value)*30;
    		f.tqblwt.value=parseInt(f.tqblw.value)*30;
    		f.out.value=parseInt(f.ou.value)*25;
    		f.but.value=parseInt(f.bu.value)*25;
    		f.gut.value=parseInt(f.gu.value)*25;
    		f.bgwst.value=parseInt(f.bgws.value)*25;
    		f.bpwst.value=parseInt(f.bpws.value)*25;
    		f.bywst.value=parseInt(f.byws.value)*25;
    		f.grandtotal.value=parseInt(f.ssgt.value)
    				  +parseInt(f.ssot.value)
    				  +parseInt(f.sswt.value)
    				  +parseInt(f.lsbt.value)
    				  +parseInt(f.lswt.value)
    				  +parseInt(f.tqbwt.value)
    				  +parseInt(f.tqbgt.value)
    				  +parseInt(f.tqmgt.value)
    				  +parseInt(f.tqblwt.value)
    				  +parseInt(f.out.value)
    				  +parseInt(f.but.value)
    				  +parseInt(f.gut.value)
    				  +parseInt(f.bgwst.value)
    				  +parseInt(f.bpwst.value)
    				  +parseInt(f.bywst.value)
    				  +parseInt(f.pht.value) }
    
    	function CalculatePost() {
    		if (f.ph.value == "dom") {
    		pht == 8; 
    	}
    		if (f.ph.value == "inte") {
    		pht == 14;
    	}
    }
    
    function refresh()
    {
    location.reload()
    }
    
    //-->
    </script>
    
    <meta name="keywords"
    		content="frc, frc clothing, street wear, surf wear, skate wear, casual clothing"> 
    
    	<meta name="description"
    		content="FRC Clothing offers a range of casual gear including tees, shirts and hats">
    
    
    <link rel=stylesheet type="text/css" href="layout.css">
    </head>
    <body>
    
     <table border=0 bgcolor="#BB0B0B" cellpadding=10 cellspacing=0>
    		<tr><td width=970 align="center">
    			<img src="page photos\collagebannermk2.jpg"
    			height=140 width=900 alt="FRC Clothing">
    			</td>
    		</tr>
    	</table>			
    
    
    			<form name="orderform" form method="post" action="mailto:myemail@mywebsite.com">
    
    				<h2>Order Form</h2>
    				
    				<table border=1>
    				<font size=2>
    				<tr><th>Qty<th>Item<th>Size<th>Back logo<th>Price<th>Total
    
    				<tr>
    				<td><input name="ssg" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Green short sleeved Tee</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select>
    				<td><select name="logo" size=1>
    				<option>With back logo
    				<option>Without back logo
    				</select>
    				<td align="right"><font size=2>$25(aud)</font>
    				<td><input name="ssgt" size=7
    					onfocus="document.orderform.sso.select();
    						 document.orderform.sso.focus();">
    				<tr>
    				<td><input name="sso" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Orange short sleeved Tee</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select>
    				<td><select name="logo" size=1>
    				<option>With back logo
    				<option>Without back logo
    				</select>
    				<td align="right"><font size=2>$25(aud)</font>
    				<td><input name="ssot" size=7
    					onfocus="document.orderform.ssw.select();
    						 document.orderform.ssw.focus();">
    				<tr>
    				<td><input name="ssw" size=3 onblur="CalculateTotals()">
    				<td><font size=2>White short sleeved Tee</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select>
    				<td><select name="logo" size=1>
    				<option>With back logo
    				<option>Without back logo
    				</select>
    				<td align="right"><font size=2>$25(aud)</font>
    				<td><input name="sswt" size=7
    					onfocus="document.orderform.lsb.select();
    						 document.orderform.lsb.focus();">
    				<tr>
    				<td><input name="lsb" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Navy long sleeved Tee</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select>
    				<td><select name="logo" size=1>
    				<option>With back logo
    				<option>Without back logo
    				</select>
    				<td align="right"><font size=2>$30(aud)</font>
    				<td><input name="lsbt" size=7
    					onfocus="document.orderform.lsw.select();
    						 document.orderform.lsw.focus();">
    				<tr>
    				<td><input name="lsw" size=3 onblur="CalculateTotals()">
    				<td><font size=2>White long sleeved Tee</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select>
    				<td><select name="logo" size=1>
    				<option>With back logo
    				<option>Without back logo
    				</select>
    				<td align="right"><font size=2>$30(aud)</font>
    				<td><input name="lswt" size=7
    					onfocus="document.orderform.tqbw.select();
    						 document.orderform.tqbw.focus();">
    				<tr>
    				<td><input name="tqbw" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Black and white 3/4 shirt</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select><td>
    				<td align="right"><font size=2>$30(aud)</font>
    				<td><input name="tqbwt" size=7
    					onfocus="document.orderform.tqbg.select();
    						 document.orderform.tqbg.focus();">
    				<tr>
    				<td><input name="tqbg" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Navy and grey 3/4 shirt</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select><td>
    				<td align="right"><font size=2>$30(aud)</font>
    				<td><input name="tqbgt" size=7
    					onfocus="document.orderform.tqmg.select();
    						 document.orderform.tqmg.focus();">
    				<tr>
    				<td><input name="tqmg" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Maroon and grey 3/4 shirt</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select><td>
    				<td align="right"><font size=2>$30(aud)</font>
    				<td><input name="tqmgt" size=7
    					onfocus="document.orderform.tqblw.select();
    						 document.orderform.tqblw.focus();">
    				<tr>
    				<td><input name="tqblw" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Royal blue and white 3/4 shirt</font>
    				<td><select name="size" size=1>
    				<option>M
    				<option>L
    				<option>XL
    				</select><td>
    				<td align="right"><font size=2>$30(aud)</font>
    				<td><input name="tqblwt" size=7
    					onfocus="document.orderform.ou.select();
    						 document.orderform.ou.focus();">
    				<tr>
    				<td><input name="ou" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Orange unifit cap</font><td><td><td align="right"><font size=2>$25(aud)</font>
    				<td><input name="out" size=7
    					onfocus="document.orderform.bu.select();
    						 document.orderform.bu.focus();">
    				<tr>
    				<td><input name="bu" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Blue unifit cap</font><td><td><td align="right"><font size=2>$25(aud)</font>
    				<td><input name="but" size=7
    					onfocus="document.orderform.gu.select();
    						 document.orderform.gu.focus();">
    				<tr>
    				<td><input name="gu" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Green unifit cap</font><td><td><td align="right"><font size=2>$25(aud)</font>
    				<td><input name="gut" size=7
    					onfocus="document.orderform.bgws.select();
    						 document.orderform.bgws.focus();">
    				<tr>
    				<td><input name="bgws" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Black/grey/white sunset cap</font><td><td><td align="right"><font size=2>$25(aud)</font>
    				<td><input name="bgwst" size=7
    					onfocus="document.orderform.bpws.select();
    						 document.orderform.bpws.focus();">
    				<tr>
    				<td><input name="bpws" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Black/purple/white sunset cap</font><td><td><td align="right"><font size=2>$25(aud)</font>
    				<td><input name="bpwst" size=7
    					onfocus="document.orderform.byws.select();
    						 document.orderform.byws.focus();">
    				<tr>
    				<td><input name="byws" size=3 onblur="CalculateTotals()">
    				<td><font size=2>Black/yellow/white sunset cap</font><td><td><td align="right"><font size=2>$25(aud)</font>
    				<td><input name="bywst" size=7
    					onfocus="document.orderform.ph.select();
    						 document.orderform.ph.focus();">
    				<tr>
    				<td colspan="7">Please check the appropriate box below for Postage + Handling
    				<tr>
    				<td>Domestic Order (Australia)<input type="radio" name="ph" value="dom" onclick="CalculatePost()">
    				<td>International Order<input type="radio" name="ph" value="inte" onclick="CalculatePost()"><td><td><td>
    				<td><input name="pht" size="7"
    					onfocus="document.orderform.ssg.select();
    						 document.orderform.ssg.focus();">
    
    				<tr>
    				<td><td><td><td><td align="right"><font size=2>Grand Total</font>
    				<td><input name="grandtotal" size=7
    					onfocus="document.orderform.ssg.select();
    						 document.orderform.ssg.focus();">
    
    				</td>
    				</tr></font>
    			</table>
    		
    <br>
    
    <font size=2>
    	When you have finished selecting your items please click on the grand total box to add up your order.
    		<b>Please add $8 for P+H for Australian orders and $14 for P+H for international orders.</b><br>
    		Note that all prices are in Australian dollars (aud), for currency conversions please use the link
    	at the bottom of the page.
    </font>
    
    
    				<h2>Shipping Address</h2> 
    				<table border=0>
    					<tr><td width=180><font size=2>First Name:<td><input type="text" size=80 name="firstname"></font>
    
    					<tr><td width=180><font size=2>Last Name:<td><input type="text" size=80 name="lastname"></font>
    						
    					<tr><td width=180><font size=2>Address:<td><input type="text" size=80 name="streetaddress"></font>
    
    					<tr><td width=180><font size=2>Address:<td><input type="text" size=80 name="streetaddress1"></font>
    
    					<tr><td width=180><font size=2>City:<td><input type="text" size=40 name="city"></font>
    
    					<tr><td width=180><font size=2>State/Province:<td><input type="text" size=40 name="stateprovince"></font>
    
    					<tr><td width=180><font size=2>Zip Code/Postal Code:<td><input type="text" size=20 name="zipcodepostalcode"></font>
    
    					<tr><td width=180><font size=2>Country:<td><input type="text" size=40 name="country"></font>
    
    					<tr><td width=180><font size=2>Email Address:<td><input type="text" size=60 name="email"></font>
    					
    					<tr><td><td align="center"><input type="submit" value="Submit order">
    					<tr><td><td align="center"><input type="button" value="Clear order form"
    										onclick="refresh()">
    									
    							 
    					
    					</td>
    					
    					</tr>
    					
    
    				</table>
    			</form>
                                    <font size=2><p>Your e-mail address will be used to confirm receipt of your order.
    						Delivery will be by Australia Post standard surface mail. If you
    						have any special requirements (Express Post, etc.), then please
    						<a href="mailto:email@mywebsite.com"> e-mail</a> us.</p></font>
    
    	 
    <div align="center"><a href="http://www.xe.com/pca/">XE.com Currency Converter</a>  |
    <a href="policy.html#privacy">Privacy Policy</a> |
    <a href="policy.html#return">Return Policy</a> |
    <a href="contact.html">Contact Us</a>
    </div>
    
    
    <script language="JavaScript">
    <!--
    	f=document.orderform;
    	f.ssg.value=0; f.sso.value=0;
    	f.ssw.value=0; f.lsb.value=0;
    	f.lsw.value=0; f.tqbw.value=0;
    	f.tqbg.value=0; f.tqmg.value=0;
    	f.tqblw.value=0; f.ou.value=0;
    	f.bu.value=0; f.gu.value=0;
    	f.bgws.value=0; f.bpws.value=0;
    	f.byws.value=0; f.ssgt.value=0;
    	f.ssot.value=0; f.sswt.value=0;
    	f.lsbt.value=0; f.lswt.value=0;
    	f.tqbwt.value=0; f.tqbgt.value=0;
    	f.tqmgt.value=0; f.tqblwt.value=0;
    	f.out.value=0; f.but.value=0;
    	f.gut.value=0; f.bgwst.value=0;
    	f.bpwst.value=0; f.bywst.value=0;
    	f.pht.value=0;f.grandtotal.value=0;
    //-->
    </script>
    
    
    
    
    </body>
    </html>
    Last edited by liorean; 06-10-2004 at 04:23 PM. Reason: [code]ified

  • #2
    New Coder
    Join Date
    May 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    post just the problem you are having trouble with please
    i made a calculator in js so i'll prolly be able to help you

  • #3
    New Coder
    Join Date
    Jun 2004
    Posts
    21
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hello there, sorry I've taken so long to reply. I haven't had time to finish the coding myself so I decided to get a local programmer to do it for me. It's been two weeks since I called him and he hasn't called me back!

    This is the function I wrote to give the variable pht a value according to which postage and handling radio button is checked in the order form.

    function CalculatePost() {
    if (f.ph.value == "dom") {
    pht == 8;
    }
    if (f.ph.value == "inte") {
    pht == 14;

    The following is the code to actually designate which postage option is checked.

    <tr>
    <td colspan="7">Please check the appropriate box below for Postage + Handling
    <tr>
    <td>Domestic Order (Australia)<input type="radio" name="ph" value="dom" onclick="CalculatePost()">
    <td>International Order<input type="radio" name="ph" value="inte" onclick="CalculatePost()"><td><td><td>
    <td><input name="pht" size="7"
    onfocus="document.orderform.ssg.select();
    document.orderform.ssg.focus();">

    This is all good and well but it just doesn't seem to work....

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    No need for the function.

    <td>Domestic Order (Australia)<input type="radio" name="ph" value="dom" onclick="pht=8" /></td>
    <td>International Order<input type="radio" name="ph" value="inte" onclick="pht=14" /></td>

  • #5
    New Coder
    Join Date
    Jun 2004
    Posts
    21
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks Glenn, guess I was making it harder than it needed to be.
    I have revised my code for the order form, removed the function and added the two variable statements you suggested but the order form still doesn't seem to actually add the value from either radio button.
    Any ideas??

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you change this line to reflect the using of the variable as opposed to using the radio button value?

    +parseInt(f.pht.value) }

    Perhaps:
    +parseInt(pht) }

    .....Willy

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Willy's right but since pht is already an integer variable, parseInt is not needed.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •