Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Changing price in shopping cart based on additions

    Hi,

    I sell, among other stuff, soap and on my website I want to give users the options to add additives to their soap. The additives cost extra. The shopping cart I am using allows me to "join" several options i.e. color, fragrance, etc. with the use of the name="product[]". My problem is that I don't know how to reference this field. I tried window.product[].value, etc. etc. Can anyone help me figure this out?

    I also tried giving the user two radio buttons and depending on which one was checked, the script increased the price or left it alone. With that I wasn't able to check if the user chose an additive without clicking the "Additive" radio button first - meaning that the price increase would not happen.

    I would appreciate any help!

    Thank you.
    Riva

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,946
    Thanks
    0
    Thanked 236 Times in 233 Posts
    you can do it like this:

    document.formNameHere.elements["product[]"].value

    the most common way is :

    document.formNameHere.fieldNameHere.value

    but since the field's name has special characters, you can't use that.

    to check if radio button is checked:

    if (document.formNameHere.radioNameHere[0].checked){
    //radio button 1 is checked
    }

    I have given you the idea, you can expand on that to suit your needs.

  • #3
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Thank you.

    I will work on it and let you know if I get stuck again. Thanks!

    :-)
    Riva

  • #4
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy I get "undefined"

    I tried alert(document.theForm.elements["product[]"].value) and it came up as undefined. ? ?

    Thanks,
    Riva

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,946
    Thanks
    0
    Thanked 236 Times in 233 Posts
    when do you call the alert? can you post the code?

  • #6
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code

    Sure. This is where I give the user the options:


    Additives:<BR>($1 extra per bar)<BR>
    <select size="1" name="product[]" onChange="newMsg()">
    <option value="selected">--
    <option value="Goatsmilk">Goatsmilk</option>
    <option value="Honey">Honey</option>
    <option value="Oatmeal">Oatmeal</option>
    <option value="Goatsmilk and honey">Goatsmilk &amp; Honey</option></select>

    And this is where I call the alert: (in the <head> section)

    function newMsg()
    {
    alert(document.theForm.elements["product[]"].value);
    }


    Thanks!

    Riva

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,946
    Thanks
    0
    Thanked 236 Times in 233 Posts
    you didn't say that it's a select field (or i didn't get it?). the code I gave you is for text fields, but that will also work in IE for select field. The correct way to get the value of the select is:

    document.theForm.elements["product[]"].options[document.theForm.elements["product[]"].selectedIndex].value;

    since that is called by the select element itself, you can simplify it like:

    <select size="1" name="product[]" onChange="newMsg(this)">
    ...

    function newMsg()
    {
    alert(this.options[this.selectedIndex].value);
    }

  • #8
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still getting errors

    I tried both options and keep getting the following error:

    "xxx is null or not an object"

    Is there some way to make two fields and then append them together right before submit?

    Thanks for the help.

    Riva

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,946
    Thanks
    0
    Thanked 236 Times in 233 Posts
    can you post the code again? are you sure you have <form> tags?

  • #10
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    More code

    Sure. Here is more of the code:

    <script language="JavaScript">
    <!--
    function newMsg()
    {
    alert(document.theForm.product.value);
    }
    -->
    //-->
    </script>
    .
    .
    .
    .
    .
    .
    <form action="http://ww5.aitsafe.com/cf/add.cfm" method="post">
    <input type="hidden" name="userid" value="******">
    <input type="hidden" name="price" value="6.00">
    <input type="hidden" name="product[]" value="Hummingbird soap">
    <input type="hidden" name="return" value="http://pages.ivillage.com/thebubblebath/products.html">
    <FONT SIZE="3" FACE="Arial">Select your fragrance:<BR>
    <select size="1" name="product[]">
    <FONT SIZE="3" FACE="Arial"><option value="selected">---
    <OPTION VALUE="Apricot Freesia">Apricot Freesia</OPTION>
    <OPTION VALUE="Baby Powder">Baby Powder</OPTION>
    <OPTION VALUE="Banana Cream">Banana Cream</OPTION>
    <OPTION VALUE="Bay Rum">Bay Rum</OPTION>
    <OPTION VALUE="Butterscotch">Butterscotch</OPTION>
    <OPTION VALUE="Cucumber Melon">Cucumber Melon</OPTION>
    <OPTION VALUE="Freesia">Freesia</OPTION>
    <OPTION VALUE="Freshly Cut Grass">Freshly Cut Grass</OPTION>
    <OPTION VALUE="Fresh Brewed Coffee">Fresh Brewed Coffee</OPTION>
    <OPTION VALUE="Gardenia">Gardenia</OPTION>
    <OPTION VALUE="Georgia Peach">Georgia Peach</OPTION>
    <OPTION VALUE="Hazelnut Cappuccino">Hazelnut Cappuccino</OPTION>
    <OPTION VALUE="Kiwi">Kiwi</OPTION>
    <OPTION VALUE="Lavender EO">Lavender ESSENTIAL OIL</OPTION>
    <OPTION VALUE="Lemon, Lemon, Lemon">Lemon, Lemon, Lemon</OPTION>
    <OPTION VALUE="Lemon Poundcake">Lemon Poundcake</OPTION>
    <OPTION VALUE="Masculine Musk">Masculine Musk</OPTION>
    <OPTION VALUE="Nutcracker">Nutcracker</OPTION>
    <OPTION VALUE="Oatmeal, Milk and Honey">Oatmeal, Milk and Honey</OPTION>
    <OPTION VALUE="Ocean Rain">Ocean Rain</OPTION>
    <OPTION VALUE="Peppermint EO">Peppermint ESSENTIAL OIL</OPTION>
    <OPTION VALUE="Pineapple">Pineapple</OPTION>
    <OPTION VALUE="Plumeria">Plumeria</OPTION>
    <OPTION VALUE="Strawberries and Cream">Strawberries and Cream</OPTION>
    <OPTION VALUE="Sun Ripened Raspberry">Sun Ripened Raspberry</OPTION>
    <OPTION VALUE="Sweet Juicy Pear">Sweet Juicy Pear</OPTION>
    <OPTION VALUE="Tangerine">Tangerine</OPTION>
    <OPTION VALUE="Tropical Paradise">Tropical Paradise</OPTION>
    <OPTION VALUE="True Lilac">True Lilac</OPTION>
    <OPTION VALUE="Unscented">Unscented</OPTION>
    <OPTION VALUE="Vanilla Cream">Vanilla Cream</OPTION>
    <OPTION VALUE="Warm Apple Pie">Warm Apple Pie</OPTION></select>
    <BR><FONT FACE="Arial" SIZE=3>Color Preference:<BR>
    <input type="text" name="product[]" size="23"><BR><BR>
    Additives:<BR>($1 extra per bar) <BR>
    <select size="1" name="product[]" onChange="newMsg(this)">
    <option value="selected">--
    <option value="Goatsmilk">Goatsmilk</option>
    <option value="Honey">Honey</option>
    <option value="Oatmeal">Oatmeal</option>
    <option value="Goatsmilk and honey">Goatsmilk &amp; Honey</option></select></TD>
    <TD VALIGN="top">
    Quantity:<BR><input type="text" name="qty" size="2" value="1">
    <BR><BR>
    <DIV ALIGN="right">
    <input type="submit" value="Add to Cart"><BR>
    <input type="submit" value="View Cart"></DIV></form>

    This is code I am working on on my computer. I haven't uploaded this yet.

    Thanks,
    Riva

  • #11
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,946
    Thanks
    0
    Thanked 236 Times in 233 Posts
    use this:

    function newMsg(objSelect)
    {
    alert(objSelect.options[objSelect.selectedIndex].value);
    }

    sorry, i gave you the wrong code in my earlier post.

    why do you have many fields named "product[]", 2 selects and 1 text field. you can't have different field type having the same name. you can name the 2 selects the same but not along with the text field. is there some reasons you name them like that?

  • #12
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update

    I will try the new code you posted - thanks.

    The "info" on how to use the shopping cart said that if you want to add options to your products, name another field "product[]" and it will append to the first one so you get all your options in the cart. It is from mal's-e-commerce.

    :-)
    Riva

  • #13
    New Coder
    Join Date
    Mar 2003
    Location
    U.S.A.
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up It works!!

    Thanks a bunch! This is great!!

    :-)
    Riva


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •