/ Published in: JavaScript
Just a prototype based method to quickly check a form for empty fields.
Expand |
Embed | Plain Text
function checkForEmptyFields (elIdArray) { var returnVal = true; var returnMsg = []; elIdArray.each( function(elId) { var el = $(elId); if (el.value.blank() === true) { returnVal = false; returnMsg.push("The element '" + el.name + "' cannot be blank."); } else {} }); return [returnVal, returnMsg]; } var checkFields = checkForEmptyFields(["firstName", "lastName", "userEmail"]); if (checkFields[0] === false) { alert(checkFields[1]); } else { $("updateProfile").submit(); }
You need to login to post a comment.
