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

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;
}

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: