This should be really simple, but I can't get it to work - I'm trying to disable 2 drop down lists when a user clicks a checkbox.
@Html.DropDownList("StartTime", new List<SelectListItem>
{
new SelectListItem{ Text="10:00 AM", Value = "10:00 AM" },
new SelectListItem{ Text="12:00 PM", Value = "12:00 PM" },
new SelectListItem{ Text="2:00 PM", Value = "2:00 PM" }
}
@Html.DropDownList("EndTime", new List<SelectListItem>
{
new SelectListItem{ Text="10:00 AM", Value = "10:00 AM" },
new SelectListItem{ Text="12:00 PM", Value = "12:00 PM" },
new SelectListItem{ Text="2:00 PM", Value = "2:00 PM" }
}
@Html.CheckBox("chkAllDayEvent", new { @onclick = "AllDayEvent_Checked();" })
<script type='text/javascript'>
function AllDayEvent_Checked() {
$("#chkAllDayEvent").click(function () {
$('#EndTime').attr("disabled", $(this).is(':checked'));
$('#StartTime').attr("disabled", $(this).is(':checked'));
});
}
</script>
My problem is that when I get to the page, the Javascript doesn't fire until I click the checkbox 3 times - on the 3rd time it disables the text boxes, then works as per normal.