I am trying to add code so when a user checks a box a certain field is enabled and another disabled and vice versa if the check box is not checked. I have looked on here and found this code:
<head>
<script type="text/javascript">
$('#UseForecast').click(function() {
var $this = $(this);
if ($this.is(':checked')) {
$('#MinimumOnHandQuantity').removeAttr("disabled");
$('#ForecastMultiplier').attr("disabled", "disabled")
} else {
$('#MinimumOnHandQuantity').attr("disabled", "disabled")
$('#ForecastMultiplier').removeAttr("disabled");
}
});
</script>
</head>
@Html.EditorFor(model => model.UseForecast, new { htmlAttributes = new { @class = "form-control" } })
@Html.EditorFor(model => model.MinimumOnHandQuantity, new { htmlAttributes = new { @class = "form-control" } })
@Html.EditorFor(model => model.ForecastMultiplier, new { htmlAttributes = new { @class = "form-control" } })
What am I missing?
Which I modified to include the ids of the fields on my page. UseForecast is the id of the checkbox, MinimumOnHandQuantity is the first textbox, and ForecastMultiplier is the id for the second textbox. When I try to step through the code, it stops when the page initially loads but it will not run whenever I click on the check box.