I'm trying to validate the form to see if the textbooks are filled. It is supposed to alert whether or not the boxes are filled after you submit, but my page isn't doing anything. I'm not sure what could be going wrong.
$(document).ready(function() {
$('#customerSubmit').click(function(e) {
var isValid = true;
$('input[type="text"]').each(function() {
if ($.trim($(this).val()) == '') {
isValid = false;
$(this).css({
"border": "1px solid red",
"background": "#FFCECE"
});
} else {
$(this).css({
"border": "",
"background": ""
});
}
});
if (isValid == false) {
e.preventDefault();
} else {
alert('Thank you for submitting');
});
});
<!DOCTYPE html>
<html>
<head>
<body>
<h3>Contact Information </h3>
<table class="customerInfo">
<tr>
<th>First Name:</th>
<td><input type="text" name="custFirstName"/></td>
</tr>
<tr>
<th>Last Name:</th>
<td><input type="text" name="custLastName"/></td>
</tr>
<div class="control-group" id="controlEmail">
<tr>
<th>Email:</th>
<td><input type="text" name="custEmail" id="email"/></td>
</tr>
</div>
</table>
<input id="customerSubmit" class="submit" type="submit" value="Submit" name="customerSubmit"/>
</body>
</html>