Developer forum

Forum » Ecommerce - Standard features » Change productid in form

Change productid in form

Per Ljung
Reply
Hi!

I have product page with a dropdownlist of related products. When choose a product in the list I want change the product id attribute of the form so that when the customer clicks the "buy-button" it's the product choosed form the list that is added to the cart.

I'v tried to update this with jquery, but it's the original product that's added to the cart and not the product I have chosen from the list.

Here is my code:
$('[name=ProductID]').val(productid);

Best regards,
P

Replies

 
Marco Johannesen
Reply
Could you paste some more code?

Normally it would be

var ProductID = $('#ProductID');
$('#selectID').change( function() {
    var NewProdID = $(this).find(':selected').val();
    ProductID.val(NewProdID);
});

But what value does the dropdown have? It mus be something like "PROD249"

Could you paste some html? :)

 
Per Ljung
Reply

<input type="hidden">

                        <xsl:attribute name="name">variant<xsl:value-of select="position()" disable-output-escaping="yes" /></xsl:attribute>

                        <xsl:attribute name="id">variant<xsl:value-of select="position()" disable-output-escaping="yes" /></xsl:attribute>

                        <xsl:attribute name="value"><xsl:value-of select="Ecom.Product.ID" disable-output-escaping="yes" /></xsl:attribute>

                      </input>
var productid = $('#variant' + ($('#variantlist').prop('selectedIndex') + 1)).val();

alert($('[name=ProductID]').val());
//The alert statements shows the right product id.
 
Marco Johannesen
Reply
If you use firebug, and set PERSIST on, what does the post value look like?
And when do you replace the value, on change or?

Maybe you could post all the jquery or the selectbox html ;-)

 
Per Ljung
Reply

It works, I had to change the productid on the form action attribute too.

Best regards,
Per

 

You must be logged in to post in the forum