JSFiddle - React, Tailwind, and code Playground
HTML
<select id="datepicker">
<option selected="selected">Choose a date</option>
<option>-------------</option>
<option value="2/10/2011">2/10/2011</option>
<option value="3/10/2011">3/10/2011</option>
<option value="4/10/2011">4/10/2011</option>
</select>
<div id="dateDiv" style="display:none;">
<!-- This div contains dates from database -->
<ul id="dates">
<li>2/10/2011</li>
<li>4/10/2011</li>
</ul>
</div>
JavaScript
$('#datepicker').change(function() {
// Get the value of date field
var dateValue = $('#datepicker').val();
// Make and empty list
var dateList = [];
// Append all dates from <li> to dateList
$("#dates li").each(function() {
dateList.push($(this).text());
});
// Perform the match
if ($.inArray(dateValue, dateList ) > -1) {
alert("Date matched!!!");
} else {
alert("Sorry. Try again.");
}
});