I have 3 <select> elements for Day, Month and Year. And I am trying to get them validated with jQuery.
<li class="pseudo_day">
<select class="mod_day" name="day">
<option disabled selected>Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</li>
Like so:
$("select[name=day], select[name=month], select[name=year]").on('change', function(){
var select_day = $("select[name=day]").val();
var select_month = $("select[name=month]").val();
var select_year = $("select[name=year]").val();
if ( select_day.length !== 0 ) { console.log("Valid - " + select_day); }
else { console.log("Not valid!"); }
});
This is the error I get when I run the jQuery code:
Uncaught TypeError: Cannot read property 'length' of null
at HTMLSelectElement.<anonymous> (new_user.html:242)
at HTMLSelectElement.dispatch (jquery-3.2.1.min.js:3)
at HTMLSelectElement.q.handle (jquery-3.2.1.min.js:3)
What am I doing wrong here?