Created
October 26, 2018 15:06
-
-
Save acbrent25/510845ff9a4d260ba08a0e19fc599ec1 to your computer and use it in GitHub Desktop.
Custom Validation Messaging for Form Selects with Bootstrap and jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="/" method="post" enctype="multipart/form-data"> | |
<div class="form-group"> | |
<label for="select_validation">Select Validation: *</label> | |
<select class="form-control" name="select_validation" id="select_validation"> | |
<option value="">Make Selection</option> | |
<option value="selectOne">selectOne</option> | |
<option value="selectTwo">selectTwo</option> | |
<option value="selectThree">selectThree</option> | |
</select> | |
</div> | |
</form> | |
<button class="btn btn-success sub-btn" type="submit">Save</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
$('.sub-btn').click(function(){ | |
var selectOne = $('#selectOne'); | |
var selectTwo = $('#selectTwo'); | |
var selectThree = $('#selectThree') | |
var alertMessage = []; | |
if (selectOne.val() === ''){ | |
alertMessage.push("Please Select a selectOne"); | |
$('.alert').text(alertMessage).show(); | |
return false; | |
} | |
if (selectTwo.val() === ''){ | |
alertMessage.push("Please Select a selectTwo"); | |
$('.alert').text(alertMessage).show(); | |
return false; | |
} | |
if (selectThree.val() === ''){ | |
alertMessage.push("Please Select a selectThree"); | |
$('.alert').text(alertMessage).show(); | |
return false; | |
} | |
else return; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment