Question

I have a question about manipulation param in jQuery.
I need to build a URL.

This is my code:

function CollectMenuElemente(sender, eventArgs) {

    var VID = $('input[id$=hfVermittlerID]').val();
    var obj = { ID: VID };

    for (var i = 0; i < 9; i++) {
        var tbVal = $('#txtMenuElement' + i).val()
        obj += { pa: tbVal };
    }
}

How can I add dynamically param to my object obj?

Was it helpful?

Solution

You can use $.extend() to add to obj

$.extend(obj, {
    pa: tbVal
});

Note: The variable pa must be different otherwise it will just replace the existing object pa

Update

for (var i = 0; i < 9; i++) {
    var tbVal = $('#txtMenuElement' + i).val()
    obj["pa" + i] = tbVal
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top