javascript - show multiple alert in one message in jquery -
i have multiple required field controls on aspx form.
now want show validation message on button click if not filled or checked.
i want on 1 message in jquery.
here jquery code:-
$(document).ready(function () { $('#btnsave').click(function (e) { if (!validatetitle() || !validateprefix() || !validatetextboxes()) { e.preventdefault(); } }); function validatetitle() { if ($("#ddltitle").val() > "0") { if ($("#ddltitle").val() == "1104" && $("#txttitle").val() === "") { alert("please enter text in other title"); return false; } return true; } else { alert('please select title'); return false; } } function validateprefix() { if ($("#ddlprefix").val() > "0") { if ($("#ddlprefix").val() == "1110" && $("#txtprefix").val() === "") { alert("please enter text in other prefix"); return false; } return true; } else { alert('please select prefix'); return false; } } function validatetextboxes() { if ($("#txtfirstname").val() === "") { alert('first name required'); return false; } if ($("#txtmiddlename").val() === "") { alert('middle name required'); return false; } if ($("#txtlastname").val() === "") { alert('last name required'); return false; } if ($("#txtfathername").val() === "") { alert('father name required'); return false; } if ($("#txtcurrentcompany").val() === "") { alert('current company required'); return false; } if ($("#txtdateofjoin").val() === "") { alert('date required'); return false; } if ($("#txtcurrentexp").val() === "") { alert('current experience required'); return false; } return true; } });
try below code
var errarr = []; $(document).ready(function () { $('#btnsave').click(function (e) { e.preventdefault(); validatetitle(); validateprefix(); validatetextboxes(); if(errarr.length > 0) { alert(errarr.join("\n")); errarr = []; return false; } }); function validatetitle() { if ($("#ddltitle").val() > "0") { if ($("#ddltitle").val() == "1104" && $("#txttitle").val() === "") { errarr.push("please enter text in other title"); } } else { errarr.push('please select title'); } } function validateprefix() { if ($("#ddlprefix").val() > "0") { if ($("#ddlprefix").val() == "1110" && $("#txtprefix").val() === "") { errarr.push("please enter text in other prefix"); } } else { errarr.push('please select prefix'); } } function validatetextboxes() { if ($("#txtfirstname").val() === "") { errarr.push('first name required'); } if ($("#txtmiddlename").val() === "") { errarr.push('middle name required'); } if ($("#txtlastname").val() === "") { errarr.push('last name required'); } if ($("#txtfathername").val() === "") { errarr.push('father name required'); } if ($("#txtcurrentcompany").val() === "") { errarr.push('current company required'); } if ($("#txtdateofjoin").val() === "") { errarr.push('date required'); } if ($("#txtcurrentexp").val() === "") { errarr.push('current experience required'); } } });
Comments
Post a Comment