Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 3 of 3

Thread: jquery to change product chosen

  1. #1
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default jquery to change product chosen

    I have my pages populate the price and addtocartbutton with jquery. I thought just changing the value of the following hidden field would then add the item that was chosen to the cart. What else needs changed to do this?

    Code:
    <input type="hidden" name="VariantID_5891_10363" id="VariantID_5891_10363" value="10363">

  2. #2
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Do you really have a VariantID that is 5891_10363 ??


    TTFN

    BFG

  3. #3
    webopius is offline Senior Member
    Join Date
    Nov 2008
    Location
    London, UK
    Posts
    440

    Default

    Hi

    When I use JQuery to auto-add items to the cart, I usually call the AddToCart.aspx page using a JQuery Ajax call.

    I find this makes life a lot simpler because you can ignore/remove all the existing addtocart Javascript (and even the AddToCart function in the XmlPackages) and replace it with something like this:

    Code:
    var $url = "addtocart.aspx?Quantity="+$qty+"&ProductID="+$productid+"&VariantID="+$variantid+"&returnurl=/shoppingcart.aspx"; 
    	
    	$.ajax({
    	  url: $url,
    	  success: function(data) {	      
    // Do something here to show the user what's happened. e.g. minicart, alert etc.	
    	  }
    	});
    This is a simple example without color/size but you can add these also if you like. Obviously, you need to create the $qty, $productid, $variantid variables as required.

    You get complete control over what's going on, you can put this on any page and because you've probably removed all the existing Javascript, it also makes the page source much tidier and arguably more search engine friendly.

    Adam
    Webopius.com