views:

50

answers:

1

I am using the following code to build object for posting via ajax:

eval('var prop = { ' + input.attr('name') + ': inputVal };');
paramsObj = $.extend(paramsObj, prop);

Unfortunately I am having a little trouble when parsing my form when it comes to radios/checkboxes as I need to concatinate the values into a single param.

How can I check if paramsObj has an object called input.attr('name'), so I can change it rather than setting it

Thanks

+3  A: 
var propName = input.attr('name');
if (paramsObj.hasOwnProperty(propName)) {
    console.log('prop found');
} else {
    console.log('prop not found');
}

PS. Don't use eval. Ever.

You can get the same effect you have in eval with following code and it's much safer:

var prop = {};
prop[input.attr('name')] = inputVal;
RaYell