Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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 November 13th, 2006, 10:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default shopping cart problem

I've got a problem with a shopping cart - I have some code that works fine but I need to convert a number to a string in order to pass the variable to the next page:

this is part of the code:

function CalcForm(theSel){
    var qty = Math.round(theSel.options[theSel.selectedIndex].value);
    if(qty == 1){
        var total = 2.17+1.20;
        document.myform.shipping.value = "£1.20";
    }else if(qty == 2){
        var total = 4.34+2.40;
        document.myform.shipping.value = "£2.40";

I need the 'qty == 2' for example to be 2 x product instead of 2;

Further on in the page I have a select box for the values:

 <select name="qty" onChange="CalcForm(this);">
                                      <option value="1" selected>Twin pack &pound;2.17</option>
                                      <option value="2">2 x Twin pack &pound;4.34</option>
                                                            </select>

I need the option value to read 2 x product or 1 x product, not just 1 or 2.

I'm stuck as to how to do this - can anyone help?

thanks

Adam

 
Old November 14th, 2006, 02:12 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Adam !!

Hope this will help you

<script>
function CalcForm(theSel)
{

    var qty = Math.round(theSel.options[theSel.selectedIndex].value);

   var qtyAmount =parseFloat((theSel.options[theSel.selectedIndex].text).split("£")[1]);



   if(qty == 1)
    {
        var total = qtyAmount+1.20;
        document.myform.shipping.value = "£1.20";
       document.myform.total.value = "£"+total;

    }
 else if(qty == 2){
        var total = qtyAmount+2.40;
        document.myform.shipping.value = "£2.40";
        document.myform.total.value ="£"+total;
    }


}

</script>

<form name="myform">
<table>
<tr><td>Quantity</td>
<td>
 <select name="qty" onChange="CalcForm(this)">
                                      <option value="1" selected>Twin pack &pound;2.17</option>
                                      <option value="2">2 x Twin pack &pound;4.34</option>
                                                            </select>
</td>
</tr>
<tr>
<td>Shipping</td>
<td><input type=text readonly name="shipping"></td>
</tr>

<tr>
<td>Total</td>
<td><input type=text readonly name="total"></td>
</tr>
</table>
</form>

Cheers :)

vinod
 
Old November 14th, 2006, 12:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

thanks Vinod, will give it a try!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13: shopping cart problem mysecondlove BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 April 9th, 2008 06:48 PM
shopping cart problem...! preetham.sarojavenkatesh Visual Studio 2005 1 November 13th, 2007 12:29 PM
Problem With Total in the Shopping Cart learningASP.Net BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 October 27th, 2007 09:33 AM
Problem with session on Shopping Cart comicghozt .NET Framework 1.x 6 September 21st, 2006 09:22 AM
having problem with shopping cart radonfile Classic ASP Databases 0 September 26th, 2003 12:42 PM





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