Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript 2nd Edition
|
BOOK: Beginning JavaScript 2nd Edition For questions about Beginning Javascript 2nd Edition by Paul Wilton. (ISBN: 0-7645-5587-1). Published April 2004. For Javascript questions not specific to this book, please see the Javascript forum. If you have the 1st edition, please continue to use that forum instead at: http://p2p.wrox.com/forum.asp?FORUM_ID=21
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2005, 06:33 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default forms javascript calculating total amounts

Hi guys i have the following html im just wondering how will i go about selecting a product from the list then automatically on the change showing its unique cost in the cost text field.

Then depending on the quantity purchased of that product selection and what radio button is checked (cheque add 2$ total) (credit card increase total by 1.5 %) (cash add $5 to the total amount) and calculate the total amount of the product.

So by quantity of product and cost
and also add the exstra cost of what radio button is selected

this is my html so far how can i use my javascript with my html to do this. How would i write the function?

<SELECT NAME="mylist" onchange="this.form.mycost.selectedIndex=this.sele ctedIndex;">
<OPTION VALUE="m1">Canora Stratocaster
<OPTION VALUE="m2">Fender Stratocaster
<OPTION VALUE="m3">Guild Electric
<OPTION VALUE="m4">Gibson Flying V
<OPTION VALUE="m5">Monterey
</SELECT><br></td></tr>
<tr> <td align="left">Cost</td> <td align="left">

<input type = "text" name = "mycost" id="mycost" size="20">

<SELECT NAME="mycost">
<OPTION VALUE="m1">$500.00
<OPTION VALUE="m2">$1000.00
<OPTION VALUE="m3">$200.00
<OPTION VALUE="m4">$400.00
<OPTION VALUE="m5">$3000.00
</SELECT><br></td></tr>
<tr> <td align="left">Are there anymore items</td>
      <td align="left"><input type="checkbox" value="Age" size="20">Yes/No</td></tr>
<tr> <td align="left">Method of Payment</td>
      <td align="left"><input type="radio" value="Cash" name="pay" size="20">
      Credit<input type="radio" value="Credit" name="pay"size="20">
      Cheque<input type="radio" value="Direct Debit" name="pay"
size="20">Direct Debit<br></td></tr>

<tr> <td align="left">Quantity</td><td align="left"><input type="text" size="5" name="qty"></tr>

<tr><td align="left">Total</td><td align="left"><input type="text" name="total" onBlur="parseelement(this)"></tr>



           <tr><td align="left">Checkout</td>
          <td align="left"><input type="submit" value="checkout"></td></tr>


            </table>
             </form>




         <td align="center" valign="top"></td>






         </tr>
         <tr><td align="center" colspan="2">


         Copyright © 2000, Underground Music, All Rights Reserved.


         </td></tr></table>

         <p>
    <a href="http://validator.w3.org/check?uri=referer"><img
        src="http://www.w3.org/Icons/valid-html401"
        alt="Valid HTML 4.01 Strict" height="31" width="88"></a>
  </p>





</body>
</html>



how can that be done in html any idea's

 
Old September 26th, 2005, 08:33 AM
Authorized User
 
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hope this will get you on the right track


[font=Verdana]<form name="form1" method="post" action=""><SELECT NAME="mylist" onchange="go()">
<OPTION VALUE="500">Canora Stratocaster</option>
<OPTION VALUE="1000">Fender Stratocaster</option>
<OPTION VALUE="200">Guild Electric</option>
<OPTION VALUE="400">Gibson Flying V</option>
<OPTION VALUE="3000">Monterey</option>
</SELECT>
  <br>
  <br>
  </td></tr>
<tr> <td align="left">Cost</td>
<td align="left">$

  <input name="price" type="text" id="price">
  <br> <br></td></tr>
<tr> <td align="left">Method of Payment</td>
      </tr><tr><td align="left">&nbsp;</td>
      <td align="left"><input type="radio" value="cc" name="pay" size="20">
      Credit<input type="radio" value="chq" name="pay"size="20">
      Cheque<input name="pay" type="radio" value="cash"
size="20" checked>
      Cash<br></td></tr>

<tr> <td align="left">Quantity</td><td align="left"><input type="text" size="5" name="qty" onChange="go2()"></tr>

<tr><td align="left">Total</td><td align="left"><input type="text" name="total" onBlur="parseelement(this)"></tr>



           <tr><td align="left">Checkout</td>
          <td align="left"><input type="submit" value="checkout"></td></tr>


            </table>
            <input name="totalA" type="hidden" id="totalA">
</form>




         <td align="center" valign="top"></td>






         </tr>
         <tr><td align="center" colspan="2">


         Copyright © 2000, Underground Music, All Rights Reserved.


         </td></tr></table>
</form>
<script language="javascript">


function go(){

var initP = document.form1.mylist.options[form1.mylist.selectedIndex].value
document.form1.price.value = initP;
}
function go2(){
var total,type;
var amount = parseInt(document.form1.qty.value);
total = (parseInt(document.form1.price.value) * amount);
var l = document.form1.pay.length;


    document.form1.total.value = total;
}



</script>[/font=Verdana]






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in calculating total sales in MDX query jaee SQL Server 2000 0 March 9th, 2007 11:10 AM
calculating grand total blkskullwork Javascript 2 December 18th, 2006 10:36 AM
Calculating total form! require assistance Neeko Java Basics 1 May 4th, 2006 06:48 AM
Acrobat forms with Javascript tdmpatio Java Basics 1 March 28th, 2006 05:00 AM
Storing Large Amounts Of Data TSEROOGY Classic ASP Databases 3 October 26th, 2004 02:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.