JavaScript - Simplecart Js Quantity Shipping Help Please
Similar TutorialsI am trying to combine shipping across different items in a javascript shopping cart. I can comine shipping based on how many items are in the cart, and characteristics of the item being added. But not both. I need the script to combine shipping based on how many items are in the cart, as well as the item name of the item being added to the cart. I assume I need to check the cart quantity in 1 function, then have it call 1 of 2 other functions based on how many items are in the cart. The 2nd function would charge the shipping based on the item name. I don't know if the code is wrong, and where I should put the 2 additional functions I am adding. It isn't working though. I am adding 2 ways I have tried below. Code: me.shipping = function(){ switch(me.quantity){ case '0': return 0; break; case '1': return oneItemInCart(); break; default: otherNumber; return moreThanOneItemInCart(); break; } function oneItemInCart(); { if(item.name) { if(item.name.match = "Cricut Cartridge") return 4.39 else if(item.name.match = "Glitter") return 5.00 else return quantity*0.00; } } function moreThanOneItemInCart(); { if(item.name) { if(item.name.match = "Cricut Cartridge") return item.quantity*3.00-3.00+4.39 if(item.name.match = "Glitter") return item.quantity*4.00-4.00+5.00 else return quantity*0.00; } } Code: me.shipping = function(){ if( parseInt(me.quantity,10)===0 ) return 0; else if( parseInt(me.quantity,10)===1) return oneItemInCart(); else if( parseInt(me.quantity,10) > 1) return moreThanOneItemInCart(); else return quantity*0.00; function oneItemInCart(); { if(item.name) { if(item.name.match = "Cricut Cartridge") return 4.39 else if(item.name.match = "Glitter") return 5.00 else return quantity*0.00; } } function moreThanOneItemInCart(); { if(item.name) { if(item.name.match = "Cricut Cartridge") return item.quantity*3.00-3.00+4.39 if(item.name.match = "Glitter") return item.quantity*4.00-4.00+5.00 else return quantity*0.00; } } Here is the original document - the part I edited is the me.shipping part http://simplecartjs.com/ I have now resolved please delete.
I'm using simpleCart.js (http://simplecartjs.com ) on http://yogasports.biz and have run into issues. I would like the checkout page to allow items to be removed or quantities edited and it is currently not allowing it. The javascript is located at http://yogasports.biz/simpleCart.js Also there are additional shipping options that are not appearing upon checkout yet they are declared in the paypal account. I'm unsure of what to edit in the javascript file so that they will appear. I have a form that is working just fine the only thing is that I need to add a quantity field that will update the price. Can anyone help me with this please. I am not that good at javascript as you can see. I have gotten snippet from here and there to be able to create this form. Here is the code that I have at he moment: Code: <script type="text/javascript"> florida_tax_rate = .07; function update_price(radio) { price = parseFloat(radio.getAttribute("price")); shipping = parseFloat(document.getElementById("shipping").innerHTML); subtotal = document.getElementById("subtotal"); grand_total = document.getElementById("grand_total"); subtotal.innerHTML = price; grand_total.innerHTML = (shipping + price).toFixed(2); update_tax(); } function update_tax() { menu = document.getElementsByName("ShippingState")[0]; state = menu.value; is_florida = state.match(/^(florida|fl)$/i); price = parseFloat(document.getElementById("subtotal").innerHTML); shipping = parseFloat(document.getElementById("shipping").innerHTML); real_subtotal = price + shipping; taxes = 0.00; if (is_florida) { taxes = real_subtotal * florida_tax_rate; } grand_total = document.getElementById("grand_total"); document.getElementById("taxes").innerHTML = taxes.toFixed(2); grand_total.innerHTML = (real_subtotal + taxes).toFixed(2); } </script> <form> <input onchange="update_price(this);" type="radio" name="package" value="non-chamber" price="450.00" /> Non-Chamber Member (Qty: 0-5)<br /> <input name="non-chamber qty" type="text" id="non-chamber qty" value="" size="5" maxlength="999" /> Please Enter Your Quantity <br /> <input onchange="update_price(this);" type="radio" name="package" value="chamber" price="425.00" /> Chamber Member (Qty: 0-5)<br /> <input name="chamber qty" type="text" id="chamber qty" value="" size="5" maxlength="999" /> Please Enter Your Quantity <br /> <input onchange="update_price(this);" type="radio" name="package" value="standard" price="400.00" /> Bulk Orders (Qty: Over 5)<br /> <input name="bulk qty" type="text" id="bulk qty" value="" size="5" maxlength="999" /> Please Enter Your Quantity <br /> <br /><br /> <div style="display:none;"><select onchange="update_tax();" name="ShippingState"> <option value="Florida" selected="selected">Florida</option> </select></div> <br /> Subtotal: $<span id="subtotal">0.00</span><br /> <div style="display:none;">Shipping: $<span id="shipping">0.00</span><br /></div> Taxes: $<span id="taxes">0.00</span><br /> Grand Total: $<span id="grand_total">0.00</span><br /> <br /> <img src="http://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" onClick="document.paypalPayment.submit();" /> <input type="hidden" name="process" id="process" value="1" /> </form> Thanks I have an online shopping cart and some of the products are sold in boxes of 6. So I am trying to write some code that will alert the customer if they have entered a quantity that isn't some multiple of six. I've tried using the modulus operator as well as dividing by 6 and then checking to see if the result is a whole number but inevitably the alert box pops up no matter what I enter. This is what I'm trying to use now: Code: <head> <script type="text/javascript"> function calculate(qtyordered) { if (qtyordered%6!=0) { alert("Blades are sold in boxes of 6." + '\n' + "Please correct your order quantity."); return false; } else { return true; } } </script> </head> <body> <form action="http://ww4.aitsafe.com/cf/add.cfm" onsubmit="return calculate(qtyordered)" method="post"> <input name="qtyordered" type="text" value="0" size="4" maxlength="4"> </body> What am I doing wrong? Is there a better way to check if the entered quantity is a multiple of 6? I've been given this ridiculous assignment where I have to create a shopping web page. I really need help finding the javascript codes that will allow the user to update their total as they enter the quantities of the different products in the assigned text boxes. I don't even know where to start because we were never taught how to do this in class! The question in the book says: Many companies normally charge a shipping and handling fee for purchases. Create a Web page that allows a user to enter a purchase price into a text box; include a JavaScript function that calculates shipping and handling. Add functionality to the script that adds a minimum shipping and handling fee of $1.50 for any purchase that is less than or equal to $25.00. For any orders over $25.00, add 10% to the total purchase price for shipping and handling, but do not include the $1.50 minimum shipping and handling fee. The formula for calculating a percentage is price*percent/100. After you determine the total cost of the order (purchase plus shipping and handling), display it in an alert dialog box. This is what I have so far, it comes up with the text box, but when the price is entered it doesn't come back with an answer. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="js_styles.css" type="text/css" /> <title>Calculating Shipping & Handling</title> <script type="text/javascript"> /* ![CDATA[ */ function getShipping(); { if (price <= 25.00) shipping = 1.50 else if(price > 25.00) shipping = (price * (10/100)); } /* ]]> */ </script> </head> <body> <script type="text/javascript"> /* ![CDATA[ */ document.write("<h1>Purchase Price with Shipping</h1>"); /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ var price=prompt("What is your purchase price?"); getShipping(); document.write ("<p>The purchase price entered is $" + (price) + "</p>"); document.write ("<p>Shipping is $" + (shipping) + "</p>"); var total = price + shipping; document.write("Your total price with shipping is $ " + (total) + ""); /* ]]> */ </script> </body> </html> I am having difficulty getting the following assignment to run properly: Many companies charge a shipping and handling charge for purchases. Create a Web page that allows a user to enter a purchase price into a text box and includes a JavaScript function that calculates shipping and handling. Add functionality to the script that adds a minimum shipping and handling charge of $1.50 for any purchase that is less than or equal to $25.00. For any orders over $25.00, add 10% to the total purchase price for shipping and handling, but do not include the $1.50 minmum shipping and handling charge. The formula for calculating a percentage is price * percent / 100. For example, the formula for calculating 10% of a $50.00 purchase price is 50 * 10 / 100, which results in a shipping and handling charge of $5.00. After you determine the total cost of the order (purchase plus shipping and handling), display it in an alert dialog box. Save the document as CalcShipping.html. This is what I have after working on it round and round for 4 hours yesterday: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Calculate Order</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="js_styles.css" type="text/css" /> <script type="text/javascript"> /* <![CDATA[ */ function applyShipping(shipping) { if (purchase > 25.00) shipping = purchase * 10 / 100; } /* ]]> */ </script> </head> <body> <script type="text/javascript"> /* ![CDATA[ */ document.write("<h1>Purchase Plus Shipping</h1>"); /* ]]> */ </script> <script type="text/javascript"> /* <![CDATA[ */ var purchase=window.prompt("Please Enter Your purchase amount"); var shipping = 1.50; applyShipping(); document.write ("<p>The price entered was $" + (purchase) + "</p>"); document.write ("<p>Shipping and Handling $" + (shipping) + "</p>"); var totalPrice = purchase + shipping; document.write ("<p>Your total price is $" + (totalPrice) + "</p>"); // window.alert("Your total price is $" + (totalPrice) + );// /* ]]> */ </script> </body> </html> Right now this javascript shopping cart works to 1. charge shipping based on the item, 2. the destination country, 3. it combines shipping for a quantity over 1 of the SAME item. Each item has 2 different possible shipping charges. I am trying to get the javascript to check the shopping cart to see what item in the cart has the highest possible shipping charge, charge that amount to that item, and charge the lowest possible shipping charge on all other items in the cart. If item A is purchased alone shipping is $5.00. If purchased with item B, which costs $10.00 to ship alone, the $10.00 is charged for item B and only $3.00 for item A. Because item B had the higher shipping charge at a quantity of one. I have tried adding various things like me.items[current], item.shipping, me.shipping, this.shipping, shipping_Cost, and other things next to the second && in the part of the script that shows the country. I have also tried adding && if (me.whatever) and && if (item.whatever) and similar things at the beginning of the script next to if (this.country). I have found the parts of the script that pertain to cart items and to updating the shopping cart. Now I am stuck. The javascript is in 2 parts. One part goes in the item page, which I will post first. The second part goes in an external javascript file which I will post at the bottom. In between there is the part that shows the shopping cart. It isn't part of the javascript. Code: <script type="text/javascript" src="simpleCart.js"></script> <script type="text/javascript"> <!-- simpleCart.checkoutTo = PayPal; simpleCart.email = "my Paypal email address"; simpleCart.cartHeaders = ["Name" , "Price" , "Quantity" , "remove" ]; CartItem.prototype.shipping=function(){ // we are using a 'country' field to calculate the shipping, // so we first make sure the item has a country if(this.country){ if( this.country == 'United States' && this.quantity == '1'){ return this.quantity*5.00; } else if( this.country == 'United States' && this.quantity >= '2') { return this.quantity*3.00; } else if( this.country == 'Belgium' && this.quantity == '1') { return this.quantity*12.00; } else if( this.country == 'Belgium' && this.quantity >= '2') { return this.quantity*9.00; else { return this.quantity*0.00; } } else { // use a default of $0.00 per item if there is no 'country' field return this.quantity*0.00; } } // --></script> Code: <div style="display:block;"></div> <div>SHOPPING CART</div> <div class="cartHeaders"></div><br><br><br> <div class="simpleCart_items"></div> <div id="totals"> Item Total: <span class="simpleCart_total"></span><br>Shipping Total: <span class="simpleCart_shippingCost"></span><br>Tax: <span class="simpleCart_taxCost"></span><br>Final Total: <span class="simpleCart_finalTotal"></span> </div> <br><br><br><br> <br><br> <a href="javascript:;" class="simpleCart_empty">Empty Shopping Cart</a><br><br> <a href="javascript:;" class="simpleCart_checkout">Checkout Through Paypal</a> </div></div> separate javascript file is here http://simplecartjs.com/documentation.html Hello all, I am trying to copy the billing information to be the same as the shipping information when they select the checkbox. Everything seems to work except for the State field which is a drop down. Depending on what country they select, the state field will automatically populate. Does anyone know how I can copy the billing state to be the same as shipping as well? Text file attached. Thanks in advance. Hi, PanM here. Trying to build a website to help my cousin sell his beautiful art. I am using a free web page at weebly.com and they have an option to use either PayPal or Google Checkout to put in shipping costs and go to the cart checkout. However, haven't evaluated Google yet, but PayPal does not do what I want. You have to put in various shipping prices and then it doesn't relate to the state or country unless you select all states, or anyway that's how I see it. I have found one on the net that wants $5 per month, but I am trying to do this for free. UPS, FedEx, and USPS have API's that can probably work, but I would prefer a HTML file or Javascript file in the page on my site. Can anyone help with this problem? Please. Thanks, PanM |