A new approach, multiple items/prices dropdown and static

Problems installing or using the NOP Design Free Shopping Cart. **ARCHIVE** Please post new topics to one of the groups below.

Moderator: scott

A new approach, multiple items/prices dropdown and static

Postby winkphoto » Sat Jan 04, 2003 6:29 pm

After losing a bunch of sleep after coding page upon page of multiple items with multiple prices using a previous posted bit of code that used "cases" for each of the products.. (which looked like)

Code: Select all
function AddOneOfManyToCart(formToUpdate)
{
   switch( formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex].value ) {
      case '1':
         formToUpdate.PRICE.value="10.00";
         formToUpdate.NAME.value=" 2 panel 1/0, 1/0";
         formToUpdate.ID_NUM.value="2pp1/0, 1/0";
         formToUpdate.SHIPPING.value="0.00";
         break;
      case '2':
         formToUpdate.PRICE.value="13.00";
         formToUpdate.NAME.value="2 panel 1/1, 1/1";
         formToUpdate.ID_NUM.value="2pp1/1, 1/1";
         formToUpdate.SHIPPING.value="0.00";
         break;
default:
         alert('Please select a product');
         return false;
   }
   AddToCart(formToUpdate);
}
</script>



I had a catharsis... or an epiphany... or heartburn, not sure which...

I couldn't do 20 or thirty pages like this, especially since some of the pages had over 50 cases to set up.

There had to be a better way.

After some thought, I came up with this solution.

Use this code in place of the above code:

Code: Select all
<SCRIPT>
function AddOneOfManyToCart(formToUpdate)
{
   selectedObj = formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex];

   nameVal = selectedObj.getAttribute("name");
   if (nameVal == "NOTHING") {
      alert('Please select a product');
      return false;
   }

   formToUpdate.NAME.value = nameVal;

   costVal = selectedObj.getAttribute("cost");
   formToUpdate.PRICE.value = costVal;


   id_numVal = selectedObj.getAttribute("id_num");
   formToUpdate.ID_NUM.value = id_numVal;

   shippingVal = selectedObj.getAttribute("shipping");
   formToUpdate.SHIPPING.value = shippingVal;


   switch( formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex].value ) {
   }
   AddToCart(formToUpdate);
}
</script>


This code bascially reads values that are placed within the <options> tag and appends it to allow the cart to accept the values.

Use this code below as the template for your product (I'll use the examples of pictures in different sizes, since that was asked for on the forum:
Code: Select all
Firefighters Raise Flag at World Trade Center Site<br>
Choose size of image you wish. After selecting, you will be presented<br>
with framing options.<br>
<!--Shopping Cart Product Begin-->
<FORM NAME=order action="frame_options.html">
 <input type=hidden name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<input type=hidden name=PRICE value="">
<input type=hidden name=NAME value="">
<input type=hidden name=ID_NUM value="">
<input type=hidden name=SHIPPING value="">
<SELECT NAME="PRODUCTSELECTOR">

<OPTION cost="1.00" id_num="4x6print" name="4x6 print" shipping="">4x6 print

<OPTION cost="2.00" id_num="5x7print" name="5x7 print" shipping="">5x7 print

<OPTION cost="3.00" id_num="8x10print" name="8x10 print" shipping="">8x10 print

<OPTION cost="4.00" id_num="11x14print" name="11x14 print" shipping="">11x14 print

<OPTION cost="5.00" id_num="16x20print" name="16x20 print" shipping="">16x20 print

<OPTION cost="6.00" id_num="20x24print" name="20x24 print" shipping="">20x24 print

<OPTION cost="4.00" id_num="16x20calendar" name="16x20 calendar" shipping="">16x20 calendar

<OPTION cost="5.00" id_num="16x20lithograph" name="16x20 Lithograph" shipping="">16x20 Lithograph

<OPTION cost="6.00" id_num="16x20signedlithograph" name="16x20 Signed Lithograph" shipping="">16x20 Signed Lithograph

</SELECT>
<input type=image src="buynow.gif" value='  Add to Cart  ' onClick='AddOneOfManyToCart(this.form)'>
</FORM>
<!--Shopping Cart Product End  -->


The above example does a couple of things;
1- It hides the quantity field which you may or may not want to do. It puts in a value of "1" in this instance. You can use:
Code: Select all
 <input type=text size=2 maxlength=3 name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">

2- It directs the shopper to another page for additional product that may be associated with the selction they just made, in this case to a page that would have frames for the picture they just purchased.

This code and logic saves a lot of time, and it doesn't matter how many options you have, as long as you include the variables "cost -- id_num -- name -- shipping".

If you need to use a cart that has a static field instead of an option field, just use the regular code:
Code: Select all
<!--Shopping Cart Product Begin-->
<FORM NAME=order ACTION="_whichever_.html" onSubmit="AddToCart(this);">
Quantity:
<input type=text size=2 maxlength=3 name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<br>
<input type="image" src="buynow.gif" border=0 value="Add to Cart" align=top>
<input type=hidden name=PRICE value="1.00">
<input type=hidden name=NAME value="4x6print">
<input type=hidden name=ID_NUM value="4x6print">
<input type=hidden name=SHIPPING value="0.00">
Option 1:
<select name=ADDITIONALINFO>
<option value="">
<option value="">
<option value="">
</select>
<br>
<!-- <input type=button value='Add' onClick='AddToCart(this.form)'> -->
</FORM>
<!--Shopping Cart Product End  -->


I haven't done a lot fo testing with this code, so I can say it's fail safe or bullet proof, but the few times I've run it thru, it has worked ok.

Another note, this coding will not work with some older browsers as they don't handle parts of that code (which I think has to do with DOM objects, but not sure), so be sure to test, or post a requirement on yoru page for a broswer version. IE4 and above and Netscape 6 and above should be ok. Not sure what version of Mozilla would work, as I don't have it.

Hope this works for you, as it is certainly working for me!

Regards,


Marc[/code]
winkphoto
Guru
 
Posts: 176
Joined: Fri Nov 15, 2002 9:21 pm
Location: Nashua, NH

Brain freezing --

Postby winkphoto » Sun Jan 05, 2003 12:07 am

Would there be a way to use radio buttons instead of a drop down "select" options list?

I can see where it would be much easier to just click a radio button then the ADD button. Much neater in appearance.

I would want to use it in the example above, but I can't seem to get it to work.

Any ideas Scott?

Marc
winkphoto
Guru
 
Posts: 176
Joined: Fri Nov 15, 2002 9:21 pm
Location: Nashua, NH

Postby scott » Fri Jan 10, 2003 2:08 am

Sure -- all you'll need to change is instead of getting a selected index (doesn't exist for checkboxes) -- get the array lenghth, loop through the checkboxes, and for each checkbox see if it is 'checked' If so, then use the data from there just like you did with dropdowns.

-Scott
scott
Site Admin
 
Posts: 558
Joined: Sun Jul 14, 2002 7:00 pm
Location: Phoenix, AZ

Postby BadHabit » Tue Jan 21, 2003 12:55 pm

winkphoto,

I liked your thoughts of how to handle multiple items/prices dropdown and static. I tried to use your example but I can't get it to work when I add another field "ADDITIONALINFO2".

If I have the following line and run the code I get that the ADDITIONALINFO2 is null or not an object.

<input type=hidden name=ADDITIONALINFO2 value="">

If I remove the line eveything work. I want to use ADDITIONALINFO2 field as a size field. I was looking to add a size as part of the OPTION and then modify the javascript similar to the other varables to load the ADDITONALINFO2 for the cart.

<OPTION cost="4.00" size="4" name="4&quot; Decal">4&quot - $4.00

This is what I have:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT SRC="language-en.js"></SCRIPT>
<SCRIPT SRC="nopcart.js">
//=====================================================================||
// NOP Design JavaScript Shopping Cart ||
//---------------------------------------------------------------------||
// Visit NOP Design at http://www.nopdesign.com/freecart ||
//=====================================================================||
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
function AddItemToCart(formToUpdate)
{
selectedObj = formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex];
nameVal = selectedObj.getAttribute("name");
formToUpdate.NAME.value = nameVal;

costVal = selectedObj.getAttribute("cost");
formToUpdate.PRICE.value = costVal;

// id_numVal = selectedObj.getAttribute("id_num");
// formToUpdate.ID_NUM.value = id_numVal;

// shippingVal = selectedObj.getAttribute("shipping");
// formToUpdate.SHIPPING.value = shippingVal;
switch( formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex].value ) {
}
AddToCart(formToUpdate);
}
</script>

</head>
<body>

<FORM NAME=order action="managecart.htm">
<p>
Decal Size:
<input type=hidden name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<input type=hidden name=PRICE value="">
<input type=hidden name=NAME value="">
<input type=hidden name=ID_NUM value="MS02001">
<input type=hidden name=SHIPPING value="">
<input type=hidden name=ADDITIONALINFO2 value="">
<SELECT NAME="PRODUCTSELECTOR">
<OPTION cost="4.00" name="4&quot; Decal">4&quot - $4.00
<OPTION cost="5.00" name="5&quot; Decal">5&quot - $5.00
<OPTION cost="6.00" name="6&quot; Decal">6&quot - $6.00
<OPTION cost="7.00" name="7&quot; Decal">7&quot - $7.00
<OPTION cost="8.00" name="8&quot; Decal">8&quot - $8.00
<OPTION cost="9.00" name="9&quot; Decal">9&quot - $9.00
</SELECT>
</p>
<p>
<input type="button" value=' Add to Cart ' onClick='AddItemToCart(this.form)'>
<input name="Submit" type="submit" value=' Checkout '>
</p>
</FORM>

</body>
</html>
BadHabit
WebMaster
 
Posts: 19
Joined: Thu Jan 16, 2003 12:25 pm
Location: Atlanta, Georgia

The way

Postby winkphoto » Tue Jan 21, 2003 3:10 pm

the way the multiple item coding at the top of the document works, you need to specify each of the elements in each option. The multiple item/price code works for items listed in the PRODUCTSELECTOR form element.

Trying to use ADDITIONALINFO and adding a price won't work with the code I've implemented. ADDITIONALINFO, in my code, should only be used to add something that doesn't add any cost.

Your code is:
Code: Select all
<FORM NAME=order action="managecart.htm">
<p>
Decal Size:
<input type=hidden name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<input type=hidden name=PRICE value="">
<input type=hidden name=NAME value="">
<input type=hidden name=ID_NUM value="MS02001">
<input type=hidden name=SHIPPING value="">
<input type=hidden name=ADDITIONALINFO2 value="">
<SELECT NAME="PRODUCTSELECTOR">
<OPTION cost="4.00" name="4&quot; Decal">4&quot - $4.00
<OPTION cost="5.00" name="5&quot; Decal">5&quot - $5.00
<OPTION cost="6.00" name="6&quot; Decal">6&quot - $6.00
<OPTION cost="7.00" name="7&quot; Decal">7&quot - $7.00
<OPTION cost="8.00" name="8&quot; Decal">8&quot - $8.00
<OPTION cost="9.00" name="9&quot; Decal">9&quot - $9.00
</SELECT>
</p>
<p>
<input type="button" value=' Add to Cart ' onClick='AddItemToCart(this.form)'>
<input name="Submit" type="submit" value=' Checkout '>
</p>
</FORM>



When it should be something lke this:

Code: Select all
<FORM NAME=order action="managecart.htm">
<p>
Decal Size:
<input type=hidden name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<input type=hidden name=PRICE value="">
<input type=hidden name=NAME value="">
<input type=hidden name=ID_NUM value="">
<input type=hidden name=SHIPPING value=""> 
<SELECT NAME="PRODUCTSELECTOR">
<OPTION cost="4.00" name="4&quot; Decal" id_num="MS02001" shipping="0.00">4&quot - $4.00
<OPTION cost="5.00" name="5&quot; Decal" id_num="MS02001" shipping="0.00">5&quot - $5.00
<OPTION cost="6.00" name="6&quot; Decal" id_num="MS02001" shipping="0.00">6&quot - $6.00
<OPTION cost="7.00" name="7&quot; Decal" id_num="MS02001" shipping="0.00">7&quot - $7.00
<OPTION cost="8.00" name="8&quot; Decal" id_num="MS02001" shipping="0.00">8&quot - $8.00
<OPTION cost="9.00" name="9&quot; Decal" id_num="MS02001" shipping="0.00">9&quot - $9.00
</SELECT>
</p>
<p>
<input type="button" value=' Add to Cart ' onClick='AddItemToCart(this.form)'>

</p>
</FORM>




As you can see, each variable (name, cost, shipping, id_num) is listed in the form element "PRODUCTSELECTOR". The coding I implemented looks for those variables in that form element only.

If you do a regular form for a product,

Code: Select all
<FORM NAME=order action="managecart.htm">
<p>
1 inch Decal: <br>
<input type=hidden name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<input type=hidden name=PRICE value="3.00">
<input type=hidden name=NAME value="1 inch Decal">
<input type=hidden name=ID_NUM value="1in.decal">
<input type=hidden name=SHIPPING value="0.00"> 
</p>
<p>
<input type="button" value=' Add to Cart ' onClick='AddItemToCart(this.form)'>

</p>
</FORM>



then the multiple item code does nothing and the form is passed to the script as normal.


See if it works for you.

Marc
winkphoto
Guru
 
Posts: 176
Joined: Fri Nov 15, 2002 9:21 pm
Location: Nashua, NH

Postby BadHabit » Tue Jan 21, 2003 7:21 pm

winkphoto

I understand what you are saying. I guess I did not do a good job in explaining myself. I am trying to all another variable (in this case ADDITIONALINFO2) into the equation. Then I insert

<input type=hidden name=ADDITIONALINFO2 value="">

just above the

<SELECT NAME="PRODUCTSELECTOR">

and change nothing else the page gets the error message tht ADDITIONALINFO2 is null or not an object. I was going to use another varable called DESC in the OPTION list and then modify the javascript to perform the same fuction for the ADDITIONALINFO2.

THanks
BadHabit
WebMaster
 
Posts: 19
Joined: Thu Jan 16, 2003 12:25 pm
Location: Atlanta, Georgia

Ok

Postby winkphoto » Tue Jan 21, 2003 8:11 pm

The ADDITIONALINFO mechanism should be used as another " option" that doesn't add any price, example:
Code: Select all
<SELECT NAME="PRODUCTSELECTOR">
<OPTION cost="24.95" id_num="Retrofit Nut" name="Earvana Guitar Nut Set" shipping="0.00">Earvana Guitar Nut Set $24.95
<OPTION cost="12.95" id_num="Retrofit Nut Top" name="Retrofit Nut Top" shipping="0.00">Nut top $XX.XX
<OPTION cost="12.95" id_num="Retrofit Nut Bottom" name="Retrofit Nut Bottom" shipping="0.00">Retrofit Nut Bottom $XX.XX
</SELECT><br>
<SELECT NAME="ADDITIONALINFO">
<OPTION value="NONE">Choose Size
<OPTION value="1 5/8">1 5/8"
<OPTION value="1 3/4">1 3/4 Universal/Unslotted
<OPTION value="1 11/16">1 11/16"
</SELECT><br>
<SELECT NAME="ADDITIONALINFO2">
<OPTION value="NONE">Choose Neck Style
<OPTION value="Gibson">Gibson style
<OPTION value="Fender">Fender style
<OPTION value="Acoustic">Acoustic
</SELECT><br>
<SELECT NAME="ADDITIONALINFO3">
<OPTION value="NONE">Choose Color
<OPTION value="Black">Black
<OPTION value="Ivory">Ivory
</SELECT>


In this scenario, I have three different options where the cost is different, plus three additional options that specify size, color and style.

I don't know of any othe way to use the additional options feature that is coded into the shopping cart.

Regards,

Marc
winkphoto
Guru
 
Posts: 176
Joined: Fri Nov 15, 2002 9:21 pm
Location: Nashua, NH

Postby BadHabit » Wed Jan 22, 2003 3:08 am

Thanks for the suggestions. What I was trying to do, using your example, was to load the ADDITIONALINFO2 variable (which hold the decal size for me) in place of some of the other fields in your example. In my case depending on the decal size the price will vary and I was looking for a solution as to where the customer would choice a size and that would get loaded in the ADDITIONALINFO2 and load the PRICE with the cost variable in your example. I was trying to use only those field and had everything else removed from your example. I guess I will try another method.

Thanks
BadHabit
WebMaster
 
Posts: 19
Joined: Thu Jan 16, 2003 12:25 pm
Location: Atlanta, Georgia

Yeah, that won't work

Postby winkphoto » Wed Jan 22, 2003 1:33 pm

That won't work with the code I have.

The multiple item, multiple price code only works with the "PRODUCTSELECTOR" named Form element.

You could put the sixe of the decals and their price in that section, and then use ADDITIONALINFO for other, non-pricing options.

If you want, list how you want to see the decal products and what the different options you can get for it, and perhaps I can suggest something.

Marc
winkphoto
Guru
 
Posts: 176
Joined: Fri Nov 15, 2002 9:21 pm
Location: Nashua, NH

Postby BadHabit » Wed Jan 22, 2003 10:31 pm

Here is the code that I would like to work using your excellent example. For some reason when I use the ADDITIONALINFO2 field the code errors out. If I change the ADDITIONALINFO2 name to something else it works but of course the information is not written to the cart.

Thanks


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT SRC="language-en.js"></SCRIPT>
<SCRIPT SRC="cart/nopcart.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
function AddItemToCart(formToUpdate)
{
selectedObj = formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex];
costVal = selectedObj.getAttribute("cost");
formToUpdate.PRICE.value = costVal;

sizeVal = selectedObj.getAttribute("size");
formToUpdate.ADDITIONALINFO2.value = sizeVal;

switch( formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex].value ) {
}
AddToCart(formToUpdate);
}
</script>

</head>
<body>

<FORM NAME=order action="managecart.htm">
<p>
Decal Size:
<input type=hidden name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<input type=hidden name=PRICE value="">
<input type=hidden name=NAME value="Vinyl Decal">
<input type=hidden name=ID_NUM value="MS02001">
<input type=hidden name=SHIPPING value="">
<input type=hidden name=ADDITIONALINFO2 value="">
<SELECT NAME="PRODUCTSELECTOR">
<OPTION cost="4.00" size="4">4&quot - $4.00
<OPTION cost="5.00" size="5">5&quot - $5.00
<OPTION cost="6.00" size="6">6&quot - $6.00
<OPTION cost="7.00" size="7">7&quot - $7.00
<OPTION cost="8.00" size="8">8&quot - $8.00
<OPTION cost="9.00" size="9">9&quot - $9.00
</SELECT>
</p>
<p>
<input type="button" value=' Add to Cart ' onClick='AddItemToCart(this.form)'>
<input name="Submit" type="submit" value=' Checkout '>
</p>
</FORM>

</body>
</html>
BadHabit
WebMaster
 
Posts: 19
Joined: Thu Jan 16, 2003 12:25 pm
Location: Atlanta, Georgia

Here is what I would write.

Postby winkphoto » Thu Jan 23, 2003 3:07 am

Code: Select all
<html>

<head>
  <title></title>
<SCRIPT SRC="nopcart.js">
//=====================================================================||
//               NOP Design JavaScript Shopping Cart                   ||
//---------------------------------------------------------------------||
// Visit NOP Design at http://www.nopdesign.com or Info@nopdesign.com  ||
//=====================================================================||
</SCRIPT>
</HEAD>
<body>
<!-- Multiple Items and Prices -->
<SCRIPT>
function AddOneOfManyToCart(formToUpdate)
{
   selectedObj = formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex];

   nameVal = selectedObj.getAttribute("name");
   if (nameVal == "NOTHING") {
      alert('Please select a product');
      return false;
   }

   formToUpdate.NAME.value = nameVal;

   costVal = selectedObj.getAttribute("cost");
   formToUpdate.PRICE.value = costVal;


   id_numVal = selectedObj.getAttribute("id_num");
   formToUpdate.ID_NUM.value = id_numVal;

   shippingVal = selectedObj.getAttribute("shipping");
   formToUpdate.SHIPPING.value = shippingVal;


   switch( formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex].value ) {
   }
   AddToCart(formToUpdate);
}
</script>
<!-- End Multiple Items and Prices -->

<FORM NAME=order action="managecart.htm">
<p>
Decal Size:
<input type=hidden name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<input type=hidden name=PRICE value="">
<input type=hidden name=NAME value="">
<input type=hidden name=ID_NUM value="">
<input type=hidden name=SHIPPING value="">
<SELECT NAME="PRODUCTSELECTOR">
<OPTION cost="4.00" id_num="MS02001" name="4&quot Vinyl Decal" shipping="0.00">4&quot - $4.00
<OPTION cost="5.00" id_num="MS02001" name="5&quot Vinyl Decal" shipping="0.00">5&quot - $5.00
<OPTION cost="6.00" id_num="MS02001" name="6&quot Vinyl Decal" shipping="0.00">6&quot - $6.00
<OPTION cost="7.00" id_num="MS02001" name="7&quot Vinyl Decal" shipping="0.00">7&quot - $7.00
<OPTION cost="8.00" id_num="MS02001" name="8&quot Vinyl Decal" shipping="0.00">8&quot - $8.00
<OPTION cost="9.00" id_num="MS02001" name="9&quot Vinyl Decal" shipping="0.00">9&quot - $9.00
<p>
<input type="button" value=' Add to Cart ' onClick='AddItemToCart(this.form)'>
<input name="Submit" type="submit" value=' Checkout '>
</p>
</FORM>

</body>
</html>




Now, this method may seem a bit long winded (or coded) this is the way I had intended the multiple item/multiple price code to work.

The additional info fields, while they can be drop down boxes, and can add other info, such as color or size, won't work well in the way you are trying to use it.

Take the code I have up above and see if it works for you as far as making an order, sending it to the manage cart page and seeing how it looks as a "product in the cart". If it looks good, use it as a template.

If you can build the page, out it on a server, get it running so it works, THEN have some questions as to how to modify it from here, then perhaps we can see what we can do.

Regards,

Marc
winkphoto
Guru
 
Posts: 176
Joined: Fri Nov 15, 2002 9:21 pm
Location: Nashua, NH

One more thing...

Postby winkphoto » Thu Jan 23, 2003 3:10 am

One more thing... this line of code needs to change
from this
Code: Select all
<input type="button" value=' Add to Cart ' onClick='AddItemToCart(this.form)'>



to this

Code: Select all

<input type="button" value=' Add to Cart ' onClick='AddOneOfManyToCart(this.form)'>



Marc
winkphoto
Guru
 
Posts: 176
Joined: Fri Nov 15, 2002 9:21 pm
Location: Nashua, NH


Return to Installation and Setup Problems

Who is online

Users browsing this forum: No registered users and 0 guests