I’m trying to get the values of some input checkboxes and add them to a add to cart button.
Here is the button code:
<button id="product-addtocart-button" class="button btn-cart" onclick="location.href='<?php echo Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL); ?>checkout/cart/add?product=5&qty=1'">
<span>
<span>
<?php echo $this->__('Add All to Cart') ?>
</span>
</span>
</button>
See where the number “5” is, I need to have this number added dynamically according to the checkboxes that have been checked.
It needs to be like this example: product=5&qty=1
or product=5,27,18&qty=1 i.e. comma separated values.
I’m not sure javascript can do this because everything I’ve found seems like javascript needs some kind of tags to print out in. Like <div id="some-value"></div>
or it can add a value to a input field but can it add just a raw value like I need in the button above?
If it can how can I get the value from something like an input field. Like here:
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $_product["entity_id"]; ?>" name="related_products[]" value="<?php echo $_product["entity_id"]; ?>" checked>
Here are the problems I’m having with this.
~~ The pre-checked input doesn’t load when the page loads, but one has to click the checkbox first.
~~ Actually I need the checkbox to pass two values. The item id and the item price (added together, goes above the button) but one will be okay for now.
Anyhow, any help on this would be greatly appreciated.