JQuery: Validation on Disabled Option in Select Field -


i'm trying detection on select field. default first item selected disabled , acts prompt user "select option".

i want check if "disabled" item still selected when form submitted , if ask user select 1 of options in field. reason validation error throws when option selected. doing wrong?

html

<select name="purchasableid" id="metreselect" class="metre" required>   <option disabled selected>select option</option>   <option value="dynamic options">dynamic options</option> </select> 

jquery

$('#add').click(function(){    if ($(".metre").children('option').attr('disabled')) {      $('.metrevalidation').html("<span class='flash'>please select number of metres</span>");      $('.metre').addclass("errorborder");      var errormessage = 'true';   } }); 

your query $(".metre").children('option').attr('disabled') checks if there any disabled option, true. rather should check if selected option disabled:

if ($('.metre').find('option:selected').attr('disabled')) {   // show error } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -