javascript - ASP.NET MVC Razor Getting select option value -


here's code. excuse me if explain wrong.

<select class="form-control" data-val="true" data-val-number="the field  supervisorid must number." data-val-required="the supervisorid field  required." id="supervisorid" name="supervisorid"><option value=""  disabled="disabled">select supervisor</option> <option value="5" disabled="disabled">tom</option> <option value="6" disabled="disabled">john</option> </select> 

my question how access option value. tried using

   $('select[option[value*='+$val+']]').removeattribute 

i want remove attribute value selected. $val value select in checkbox , selected value gets enabled in select list. when check value 5 tom have disabled attribute removed. doesn't seem work. , tried using:

document.getelementbyid('supervisorid').options[$val].removeattribute('disabled'); 

but when value 5 or 6 , there's 2 option there isn't 5th or 6th value in list. in way when there's 2 values , check second 1 (john value 6) in select list selects 6th value of list, when there isn't one.

i first way, not options[$val] way, although appreciated. thank answers.

you can done using jquery.

 $('select option:selected').removeattr('disabled');     $(".chk").on("change",function(){         if($(this).is(":checked")){         $('select option[value="' + $(this).attr('value')+ '"]').removeattr('disabled');       }   });      
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  <select class="form-control" data-val="true" data-val-number="the field   supervisorid must number." data-val-required="the supervisorid field   required." id="supervisorid" name="supervisorid">  <option value="" disabled="disabled" selected="selected">select supervisor</option>  <option value="5" disabled="disabled">tom</option>  <option value="6" disabled="disabled">john</option>  </select>  <input class="chk" type="checkbox" value="5"  />  <input class="chk" type="checkbox" value="6"  />


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -