I have a form field with a Bootstrap Datepicker that populates an <input>
tag with a selected date.
<div class="wrapper">
<div class="form-group">
<label>Select Date</label>
<div class="input-group">
<input name="date_info" type="text" class="form-control datepick validate_date" placeholder="Date" readonly>
</div>
<small class="validate_date_error">This field is mandatory!</small>
<small class="validate_date_success">This is Fine!</small>
</div>
<button class="next">Next</button>
</div>
I want the functionality where clicking the .next
button will display .validate_date_error
if the date is not selected or empty.
If a date is selected, I want to show .validate_date_success
without needing an additional click or the [Enter] key.
Here is my JavaScript code:
$(function() {
$('.datepick').datepicker({
autoclose: true,
format: 'dd-mm-yyyy'
});
});
$(".next").click( function() {
var check_date = $(".validate_date").val();
if( check_date === "" ){
$(this).parent().find('.validate_date_error').show();
}else {
$(this).parent().find('.validate_date_error').hide();
$(this).parent().find('.validate_date_success').show();
}
});
If anyone can help me with this, I would greatly appreciate it.
You can view my updated code on JS Fiddle