I have a form with 3 select elements. Each one, by default, has option “na” and submit button is disabled. I need to enable the button when at least one of these three selectors has any other option but “na”
I am trying to write a function so that I can check for options on page load as well:
JS
function myFunction() {
bt = $(".b");
bt.attr("disabled", false).removeClass("disabledB");
if ($(".mySelect").val(":not(na)").length > 0) {
bt.attr("disabled", true).addClass("disabledB");
return false;
}
}
HTML
<table>
<tr>
<td>
<select class="mySelect">
<option value="na"></option>
<option value="1">value 1</option>
<option value="2">value 2</option>
</select>
<select class="mySelect">
<option value="na"></option>
<option value="3">value 3</option>
<option value="4">value 4</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="button" class="b" value="click me">
</td>
</tr>
</table>
Not sure what I am doing wrong.
RepWhoringPeeHaa is right. Passing a string into
$().val()means that you are attempting to set the value.$().val()cannot take a selector. I think what you want to do is usein place of