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
Post a Comment