Reputation: 153
I want to get multiple checkbox values from the listed select checkboxes on submit button. I have tried with node-event-delegate
but it's not working:
AUI().use('node', 'event', 'node-event-delegate', function (A) {
var allcheckboxes = A.one('.plans').all(':checked');
console.info(allcheckboxes.size()); // It will give number selected checkboxes
A.all('.compare-products').each(function (node) {
console.info(node.currentTarget);
console.info(node, A.one(node(':checkbox:checked')));
if (A.one(node.currentTarget).all(':checked')) {}
});
A.all('.compare-products input[type="checkbox"]').filter(':not(:checked)').setAttribute("disabled", "disabled"); // it will disable the unchecked checkboxes
A.all('.compare-products input[type="checkbox"]').filter(':not(:checked)').removeAttribute("disabled", "disabled"); // it will remove disable attribute from unchecked checkboxes
});
Upvotes: 1
Views: 1397
Reputation: 153
HTML Code
<div>
<div>
<input type="checkbox" class="product" name="product1" value="product1" /> product1<br />
<input type="checkbox" class="product" name="product2" value="product2" /> product2<br />
<input type="checkbox" class="product" name="product3" value="product3" /> product3<br />
<input type="checkbox" class="product" name="product4" value="product4" /> product4<br />
<input type="checkbox" class="product" name="product5" value="product5" /> product5<br />
</div>
<button>Compare Products</button></div>
AUI Script Code
AUI().use("node", function(A){
A.one("button").on("click", function(){
var values = [];
A.all("input[type=checkbox]").each(function(){
if(this.get("checked")){
values.push(this.get("value"));
}
});
console.log(values);
}); });
Upvotes: 3