I am trying to add the value of selected checkbox to anchor tag parameter "product-code" and "product-quantity". For example if someone click the first checkbox the product code parameter will be something like product-code="90;1" and product-quantity="1;1". And if someone also check the second checkbox the product code parameter will be like product-code="90;1;2" and product-quantity="1;1;1". Same for the third parameter. Can someone help me with this how I can get this done with the help of jquery?
<input type="checkbox" name="Apple" value="1">
<input type="checkbox" name="Banana" value="2">
<input type="checkbox" name="Orange" value="3">
<a href="#buy" class="avangate_button btn btn-primary" product-code="90" product-quantity="1">Order Now!</a>
3
Answers
its simple you just create two variables e.g productCode & productQuantity and place it anchor tag . Create a function to set upper variables value and execute this function on "onChange" event of checkbox .
here is the code :
If you really want to work with the attribute
product-code
then the following snippet should do the trick:Please note:
According to the MDM web docs the
<a>
element does not actually support an attributeproduct-code
. You should therefore rather use something likedata-product-code
instead.This solution will work for you.