issue serializing series of checkboxes for use in JQuery $.post
basically I have 4 checkboxes their values are a number.
so lets say my HTML source is like this:
<input class="extra" type="checkbox" name="checks[1]" value="1"/>
<input class="extra" checked="checked" type="checkbox" name="checks[2]" value="2"/>
<input class="extra" type="checkbox" name="checks[3]" value="3"/>
<input class="extra" checked="checked" type开发者_StackOverflow中文版="checkbox" name="checks[4]" value="4"/>
I want to post checks[] with jquery post, so that the checks stay in the specific locations. i.e server side the array looks like this:
checks[1] is empty
check[2] = 2 checks[4] = 4this is what I am trying:
var post_data = $('input[name="checks[]"]:checked').serialize();
$.post('search_item.php', { 'checks[]':post_data, . . .
Currently if I try lets say alert(post_data)
there is nothing. So I am assuming I am doing the serializing wrong?
many thanks,
This works:
var post_data = $('input[name*="checks"]:checked').serialize();
alert(post_data);
See an example: http://jsfiddle.net/YAh3e/
Try using selector $('input[name^=checks]:chcked')
精彩评论