You can assign a class to each of the elements, and then loop over that class and cross-check their type as input
$(".frmPrc").each(function(index) { if ($(this).attr("type")=="checkbox") { if ($(this).is(":checked")) { arrFrmData.push({ "ID":index, "Field":$(this).attr("id"), "Value":1, "Title":$(this).attr("title")}); } else { arrFrmData.push({ "ID":index, "Field":$(this).attr("id"), "Value":0, "Title":$(this).attr("title")}); } } else if ($(this).attr("type")=="radio") { if ($(this).is(":checked")) { arrFrmData.push({ "ID":index, "Field":$(this).attr("name"), "Value":$(this).val(), "Title":$(this).attr("title")}); } } else { arrFrmData.push({ "ID":index, "Field":$(this).attr("id"), "Value":$(this).val(), "Title":$(this).attr("title")}); } });
it's just a quick copy and paste from an old script ... as you can see, it can be shortened ... but it gives the basic idea of โโusing "required" fields ...
source share