开发者

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() }); 
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜