51 users online (0 members and 51 guests)  


  Results 1 to 5 of 5

Related

  1. Mandatory fields form    Forum: HTML Forum
    Replies: 0
  2. Required Form Fields    Forum: Javascript Forum
    Replies: 1
  3. Dynamic form fields    Forum: Website Scripts Forum
    Replies: 1
  4. The sum of two fields    Forum: HTML Forum
    Replies: 1
  5. Pre Populatated Fields    Forum: HTML Forum
    Replies: 1
  1. #1
    bobbywilldo's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2003
    Location
    ohio
    Posts
    2

    Question The sum of two fields

    I am making an order form on my website and I want to try to add two fields together. I have a drop down menu of the products to select and then i have a box for quantity. I would like to know if there is a way where when someone selects a specific product and then their desired quantity if it could add it up in a total box.

    So let's say a customer has choosen a shirt for $12 and they want 2 of them...then it would automatically add it up for them into $24 in a separate box.

    Is this possible? I'm pretty sure I have seen it somewhere, but cannot seem to find it. If anyone can help it would be greatly appreciated. thank you very much!!

    Bobby

  2. #2
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    Welcome

    This could be done with javascript and probably php, somebody will have an answer I am sure.

    The post is better suited in our scripts forum, moved

    Dave
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting

  3. #3
    Doorknob's Avatar
    Super Newbie

    Status
    Offline
    Join Date
    Jun 2002
    Location
    Malaysia
    Posts
    316
    for example, this is your form
    *******************************************
    <form action='process.asp' name=order method=post>
    <select name=product onChange='displayprice();'>
    <option value=0 selected>no product chosen</option>
    <option value=1>shirt</option>
    <option value=2>pants</option>
    <option value=3>shorts</option>
    </select>

    <select name=qty onChange='displayprice();'>
    <option value=0 selected>0</option>
    <option value=1>1</option>
    <option value=2>2</option>
    <option value=3>3</option>
    </select>

    <input type=text maxlength=6 name=totalprice disabled>
    </form>
    *******************************************

    put this in your <head>
    *******************************************
    <script language=Javascript>
    <!--
    var price = 0;
    //price list of products
    if (product == 1)
    {price=12} //shirt cost $12
    if (product == 2)
    {price=10} //pants cost $10
    if (product == 3)
    {price=6}

    function displayprice()
    {
    var pdtno = document.order.product.value;
    var qtyno = document.order.qty.value;

    document.order.totalprice.value = pdtno*qtyno
    }
    -->
    </script>
    *******************************************

    this will display the total price. i'm sure u can do the currency handling yourself. that is easy. hope that helps

  4. #4
    bobbywilldo's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2003
    Location
    ohio
    Posts
    2

    Thank you very much!

    Thanks a lot for the help. that was perfect! take care.

    Bobby

  5. #5
    dianascheffler's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2008
    Posts
    1

    Re: The sum of two fields

    I have a similar issue can you help me also. I have 8 fields that will add automatically to the total amount field. Now I want to multiple that total amount field by $3.50 for the final field (money due) what javascript do I need to make this happen. See the html below:
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    function startCalc(){
    interval = setInterval("calc()",1);
    }
    function calc(){
    one = document.autoSumForm.dosidos.value;
    two = document.autoSumForm.thinmints.value;
    three = document.autoSumForm.trefoils.value;
    four = document.autoSumForm.chocolatechip.value;
    five = document.autoSumForm.chaletcreme.value;
    six = document.autoSumForm.tagalongs.value;
    seven = document.autoSumForm.samoas.value;
    eight = document.autoSumForm.allabouts.value;
    document.autoSumForm.totalamount.value = (one * 1) + (two * 1)+ (three * 1)+ (four * 1)+ (five * 1)+ (six * 1)+ (seven * 1)+ (eight * 1); } function stopCalc(){
    clearInterval(interval);}
    // End -->
    </script>
    </head>
    <body>
    <form name="autoSumForm"><table width="550" border="0" cellpadding="0">
    <tr>
    <td width="144" rowspan="2" valign="bottom"><input type=text name="dosidos" value="" onfocus="startCalc();" onblur="stopCalc();" /></td>
    <td width="125"><div align="center"><img src="CookieSale/cookiepictures/Do-si-dos.jpg" width="125" height="107" /></div></td>
    <td width="122" rowspan="2" valign="bottom"><input type="text" name="thinmints" value="" onfocus="startCalc();" onblur="stopCalc();" /></td>
    <td width="149"><div align="center"><img src="CookieSale/cookiepictures/Thin-Mints-black-and-white.jpg" width="125" height="121" /></div></td>
    </tr>
    <tr>
    <td><div align="center">Do-si-dos</div></td>
    <td width="149"><div align="center">Thin Mints </div></td>
    </tr>
    <tr>
    <td rowspan="2" valign="bottom"><input type=text name="trefoils" value="" onfocus="startCalc();" onblur="stopCalc();" /></td>
    <td><div align="center"><img src="CookieSale/cookiepictures/Trefoils.jpg" width="125" height="92" /></div></td>
    <td rowspan="2" valign="bottom"><input type="text" name="chocolatechip" value="" onfocus="startCalc();" onblur="stopCalc();" /></td>
    <td><div align="center"><img src="CookieSale/cookiepictures/SFCC_2.jpg" width="125" height="118" /></div></td>
    </tr>
    <tr>
    <td><div align="center">Trefoils</div></td>
    <td><div align="center">Chocolate Chip</div></td>
    </tr>
    <tr>
    <td rowspan="2" valign="bottom"><input type="text" name="chaletcreme" value="" onfocus="startCalc();" onblur="stopCalc();" /></td>
    <td><div align="center"><img src="CookieSale/cookiepictures/Lemon-Chalet-Cremes-Left.jpg" width="125" height="76" /></div></td>
    <td rowspan="2" valign="bottom"><input type="text" name="tagalongs" value="" onfocus="startCalc();" onblur="stopCalc();" /></td>
    <td><div align="center"><img src="CookieSale/cookiepictures/Tagalongs.jpg" width="125" height="94" /></div></td>
    </tr>
    <tr>
    <td><div align="center">Chalet Cremes </div></td>
    <td><div align="center">Tagalongs</div></td>
    </tr>
    <tr>
    <td rowspan="2" valign="bottom"><input type="text" name="samoas" value="" onfocus="startCalc();" onblur="stopCalc();" /></td>
    <td><div align="center"><img src="CookieSale/cookiepictures/Samoas.jpg" width="125" height="106" /></div></td>
    <td rowspan="2" valign="bottom"><input type="text" name="allabouts" value="" onfocus="startCalc();" onblur="stopCalc();" /></td>
    <td><div align="center"><img src="CookieSale/cookiepictures/All-Abouts_95-Years.jpg" width="125" height="123" /></div></td>
    </tr>
    <tr>
    <td><div align="center">Samoas</div></td>
    <td><div align="center">All Abouts </div></td>
    </tr>
    <tr>
    <td valign="bottom"><input type=text name="totalamount" /></td>
    <td colspan="2">Total Amount of Packages </td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td valign="bottom"><input type="text" name="moneydue" /></td>
    <td>Total Amount Due </td>
    <td valign="bottom">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <p>&nbsp;</p>
    </form>
    </body>
    </html>



Tags for this Thread