Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get checkbox values using checkbox name using jquery

Tags:

html

jquery

I have several input checkboxes, (they name is same for send array on server).

So, I need get each value this checkboxes and I want use as selector checkbox names, this not works, help please.

<form>   <input type="checkbox" name="bla[]" value="1" />   <input type="checkbox" name="bla[]" value="2" /> </form> 

js:

$(document).ready( function () {         $("input[name=bla]").each( function () {        alert( $(this).val() );    });  }); 

DEMO

like image 737
Oto Shavadze Avatar asked Jan 07 '13 08:01

Oto Shavadze


People also ask

How check checkbox is checked or not in name jQuery?

To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);


Video Answer


1 Answers

You are selecting inputs with name attribute of "bla", but your inputs have "bla[]" name attribute.

$("input[name='bla[]']").each(function (index, obj) {         // loop all checked items     }); 

http://jsfiddle.net/26axX/

like image 117
undefined Avatar answered Sep 26 '22 06:09

undefined