I tried below event in order to reach onchange of checkbox.
@Html.CheckBox("AutoCalculateMandate", true , new { onchange = "AutoCalculateMandateOnChange" })
Javascript:
function AutoCalculateMandateOnChange() {
alert("working");
}
When i try above javascript code , alert never displays nothing(not working).
How can i enable/disable below input on Html.Checkbox value changed ?
<input type="text" id="LevyFee" class="form-control" data-required="true" ">
Any help appreciates.
Thanks.
Definition and Usage The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.
There are two events that you can attach to the checkbox to be fired once the checkbox value has been changed they are the onclick and the onchange events.
The <input type="checkbox"> defines a checkbox. The checkbox is shown as a square box that is ticked (checked) when activated. Checkboxes are used to let a user select one or more options of a limited number of choices. Tip: Always add the <label> tag for best accessibility practices!
var val = jQuery("#frameName"). contents(). find(":checkbox").is(":checked");
You can get checkbox as a element
in your function by passing this
as a reference see updated markup below
<input type="checkbox" value="check" id="AutoCalculateMandate" onchange = "AutoCalculateMandateOnChange(this)"/>
<label for="AutoCalculateMandate">
Auto Calculate
</label> <br />
Since you're using MVC so it can be achieved like this:
@Html.CheckBox("AutoCalculateMandate", true , new { onchange = "AutoCalculateMandateOnChange(this)" })
javascript
function AutoCalculateMandateOnChange(element){
document.getElementById("LevyFee").disabled = element.checked;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With