var settings = {};
$(".js-gen-settings").each(function(){
var date;
if (($(this).attr("type") === "checkbox") || ($(this).attr("type") === "radio")){//if its a checkbox
eval("settings."+this.name+" = "+$(this).is(":checked"));
}else{
date = $(this).val();
if (date == ""){
eval("settings." + this.name + " = null");
}else{
eval("settings." + this.name + " = '" + date + "'");
}
}
});
a JSON.stringify version of settings will be sent to the server using ajax.
Here, I’ve re-factored your code: