Tickboxes and Dropdown into json data?
After clicking on the Add button, I want to gather all the id's from tickboxes and the values from dropdown... and put them into json data.. what is the correct way to do thi开发者_JS百科s?
Here what I have managed below but data
did not include index/key name of dropd and ticks.
$(".add").live('click', function() {
var ticks = {};
var dropd = {};
var data = {}
$('INPUT:checked').each(function (i) {
tickID = $(this).attr("id");
ticks[i] = {
id: tickID
};
});
$('OPTION:selected').each(function (i) {
selectID = $(this).val();
dropd[i] = {
id: selectID
};
});
$.extend(data, ticks);
$.extend(data, dropd);
console.log(data);
//ajax code block here to send json data
});
var data = { checkboxes:[], dropdowns:[] }
$('input:checked').each(function () {
data.checkboxes.push({ id: $(this).attr("id") });
});
$('option:selected').each(function () {
data.dropdowns.push({ value: $(this).val() });
});
精彩评论