Archive

Posts Tagged ‘javascript get value checkbox’

javascript lấy dữ liệu từ checkbox “checkbox_name[]”

html:

<form name=”my_form”>
<input type=”checkbox” name=”my_object[]” id=”my_object[]” value=”1″>

<input type=”checkbox” name=”my_object[]” id=”my_object[]” value=”10″>
<input type=”checkbox” name=”my_object[]” id=”my_object[]” value=”100″>
</form>
javascript:

var f =  document.my_from;
var val = ”; 

f.elements[‘my_object[]’][0].value = 1;
f.elements[‘my_object[]’][1].value = 10;
f.elements[‘my_object[]’][2].value = 100;

or 

for(var i=0; i< f.elements[‘my_object[]’].length;i++){
if(f.elements[‘my_object[]’][i].checked)
     val = f.elements[‘my_object[]’][i].value;
}