In my code, I have a serialized JSON dictionary, for example:
{ BackgroundColor="F4F4F4", ShowTitle=true, NumberToShow=10}
I need to set the values โโof the corresponding form fields (using the property key).
Here's how I do it now:
function applyPreset(preset) { for (var prop in preset) { var $container = $("div#attribute-" + prop); $("input", $container).val(preset[prop]); } }
This works great for text boxes, but obviously does not work for radio flags or lists.
I was wondering if there are any smart functions in jQuery for this or should I just scroll through each input, check its type and set the value accordingly?
source share