I have a form on a page that contains two drop down lists (id & name = "clientID" & "attendanceID") and a submit button. I want the submit button to be disabled (or hidden) if either of the dropdowns are set to a value of 0, which indicates that no sensible selection has yet been made.
I have the following in the head:
<script src="~/Scripts/jquery-2.2.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('#submitnewrecord').prop('disabled', true);
function updateFormEnabled() {
if ($('#clientID').val() != 0 && $('#attendanceID').val() != 0) {
$('#submitnewrecord').prop('disabled', false);
} else {
$('#submitnewrecord').prop('disabled', true);
}
}
$('#clientID').change(updateFormEnabled);
$('#attendanceID').change(updateFormEnabled);
</script>
My select boxes are created via helpers, but the resultant HTML is:
<select id="clientID" name="clientID">
<option selected="selected" value="0">--- select client ---</option>
<option value="397">John Doe</option>
<option value="416">Fred Smith</option>
<option value="384">Albert Epstein</option>
</select>
<select id="attendanceID" name="attendanceID">
<option selected="selected" value="0">--- select category ---</option>
<option value="1">Scheduled</option>
<option value="2">Attended</option>
<option value="3">Absent - Notified</option>
<option value="4">Absent - Unexplained</option>
</select>
My submit button HTML is:
<input id="submitnewrecord" name="submitnewrecord" type="submit" value="Update" />
I am not getting any difference in behaviour of the button to when I didn't have any JS at all! I've obviously done something daft, but could anyone let me know what that is?