I have a clothing website using snipcart which currently has no built in size or color selector so i need to do it myself by putting it in the description so we can know what to send. Anyway, i need the selected value of the color and size to be echoed in the button data.
This is my code:
<?php
echo"<h4 class='ct3'>COLOR</h4>
<select id='color' name='color'>
$colorsHTML;
</select>
<h4 class='ct3'>SIZE</h4>
<select name='size' id='size'>
$sizesHTML;
</select>
<br>
<br>
<button
class='snipcart-add-item list-group-item ct3 add_to_cart' style='background-color: black; color: white;'
data-item-id='2'
data-item-name='$name'
data-item-price='$price'
data-item-weight='0'
data-item-url=''
data-item-image='$image'
data-item-description='$description'>
ADD TO CART
</button>";
?>
I need the color and size to be echoed in the button's data so it will look like this:
<?php
echo"<h4 class='ct3'>COLOR</h4>
<select id='color' name='color'>
$colorsHTML;
</select>
<h4 class='ct3'>SIZE</h4>
<select name='size' id='size'>
$sizesHTML;
</select>
<br>
<br>
<button
class='snipcart-add-item list-group-item ct3 add_to_cart' style='background-color: black; color: white;'
data-item-id='2'
data-item-name='$name'
data-item-price='$price'
data-item-weight='0'
data-item-url=''
data-item-image='$image'
data-item-description='$description COLOR=blue SIZE=XL'>
ADD TO CART
</button>";
?>
I've tried this: but i think i would need a code for it to change the button data when the value for the select input is changed
<button
class='snipcart-add-item list-group-item ct3 add_to_cart' style='background-color: black; color: white;'
data-item-id='2'
data-item-name='$name'
data-item-price='$price'
data-item-weight='0'
data-item-url=''
data-item-image='$image'
data-item-description='$description COLOR = <script type='text/javascript'>
$('#color').select(function() {
var model=$('#color').val();
alert(model);
});</script> SIZE = <script type='text/javascript'>
$('#size').select(function() {
var model=$('#size').val();
alert(model);
});
</script>'>
ADD TO CART
</button>