jquery populate form fields from json code example
Example: jquery populate form json
(function($){
$.fn.setFormData = function(data){
let t = this;
$.each(data, function(key, value) {
var ctrl = $(t).find('[name='+key+']');
switch(ctrl.prop("type")) {
case "radio": case "checkbox": case "select":
ctrl.each(function() {
if($(this).attr('value') == value) $(this).attr("checked",value);
});
break;
case "select" :
ctrl.val(value);
break;
default:
ctrl.val(value);
}
});
}
})(jQuery);
$('#form').setFormData(someData);