So I have been looking around at questions on here and I have gotten far enough to be able to disable a textbox by changing the selection of the dropdownlist, but I want to be able to enable it again if the dropdownlist goes back to its default value of <Select an Access Point>.
JQuery:
$('#selectAccessPoint').change(function () {
if ($('#selectAccessPoint :selected').val != "2147483647")
$('#newAccessPoint').attr('disabled', 'disabled');
else {
$('#newAccessPoint').removeAttr('disabled');
$('#newAccessPoint').attr('enabled', 'enabled');
}
});
HTML for textbox and dropdownlist:
`
<tr>
<td><label for ="AccessPoint" class="xl">Access Point:</label></td>
<td><%= Html.DropDownListFor(x => x.AccessPointsList.Id, Model.AccessPointsList.AccessPoints.OrderByDescending(x => x.Value.AsDecimal()), new { @id = "selectAccessPoint", @class = "info1"})%></td>
</tr>
<tr>
<td><label for ="AccessPoint" class="xl">Or Add New:</label></td>
<td><%= Html.TextBoxFor(x => x.AccessPointsList.AccessPoint, new { @id = "newAccessPoint", @class = "location info2 xl", maxlength = "250" }) %></td>
</tr>
Generated HTML:
<select class="info1" data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="selectAccessPoint" name="AccessPointsList.Id"><option value="2147483647"><Select an Access Point></option>
(there are more options in there but this is the one I am comparing against)
<input class="location info2 xl" id="newAccessPoint" maxlength="250" name="AccessPointsList.AccessPoint" type="text" value="">
Notes: attr must be used as prop gives me an error and val() also gives me an error.
$().jquery. I suggest carefully reading through the API as there are a number of elementary errors here.$in front('#selectAccessPoint:selected')and also missing the space betweenselectAccessPoint :selected- then missing () after the text.. but it would be much easier to troubleshoot if we could see the actual generated HTML