Radio button selection event in MVC
13,101
Considering the information that you have provided in your question, the following code would fulfill your expectation
@Html.RadioButtonFor(model => model.PayMode, "Cheque") Cheque
@Html.RadioButtonFor(model => model.PayMode, "Cas") Cas
@Html.TextBox("ChequeNo", null, new {id="theTextBox"})
<script type="text/javascript">
$("input[name='PayMode']").change(function () {
var selectedRadio = $("input[name='PayMode']:checked").val();
if (selectedRadio == 'Cas') {
$("#theTextBox").attr("disabled", "disabled");
} else {
$("#theTextBox").removeAttr("disabled");
}
});
</script>
Author by
user2756361
Updated on June 30, 2022Comments
-
user2756361 almost 2 years
I am a beginer ...I don't know how to write code during the radio button select change in MVC....I have used it like this
In csHTML page
@Html.RadioButtonFor(model=>Sales.Pay_Mode, true)Cheque @Html.RadioButtonFor(model=>Sales.Pay_Mode, false)Cas
This is my cs page code....Where i want write the change event code and how i get the selected value in control page.My requirement is during radio button change i want change the style of the textbox enable as false..
@Html.TextBox("ChequeNo")
-
user2756361 over 10 yearssir pls tell what is the name of 'your-radio-class' in my project.where want to declare it
-
maxs87 over 10 yearsits just example css class yuo can define your own. For example try @Html.RadioButtonFor(model=>Sales.Pay_Mode, true, new {@class="own-class"})