javascript - how to disable dropdown options less than some value using jquery -


below have year dropdown.

<select name="from_year" class="col-md-4 form-control" id="from_year">     <option value="0">select year</option>     <option value="2010">2010</option>     <option value="2011">2011</option>     <option value="2012">2012</option>     <option value="2013">2013</option>     <option value="2014">2014</option>     <option selected="selected" value="2015">2015</option>     <option value="2016">2016</option>     <option value="2017">2017</option>     <option value="2018">2018</option>     <option value="2019">2019</option>     <option value="2020">2020</option> </select> 

now ajax call year 2016. want disable options less 2016. tried following:

$('select#from_year option:lt('+payment_date[1]+')').prop("disabled", true); 

. . . payment_date[1] = 2016, no avail.

am doing wrong. help/suggestions welcome.

you can use filter() achieve this:

var year = 2016; // ajax... $('#from_year option').filter(function() {     return $(this).val() < year; }).prop('disabled', true); 

example fiddle


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -