Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 13th, 2006, 10:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old November 14th, 2006, 02:12 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Reply With Quote
  #3 (permalink)  
Old November 14th, 2006, 12:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:13 PM.


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