Radio Button Change Event
I have 2 radio buttons (for Ex: ID and name) ..
<%=Html.RadioButton("Emp","1")%> <label>ID</label> <%=Html.RadioButton("Emp","2")%> <label>Name</label> If I click Name,
<p> <%:Html.LabelFor(m => m.MyDate)%>: <%:Html.EditorFor(m => m.MyDate) %> </p> the above control should be visible false. How to do it.
$(':radio[value=2]').click(function() { // Might need to adjust the selector here based // on the field you would like to hide $('#MyDate').hide(); }); or if you want to use the .change() event:
$(':radio[name=Emp]').change(function() { // read the value of the selected radio var value = $(this).val(); if (value == '2') { $('#MyDate').hide(); } }); Use a different approach ...
<form method="post" id="ChangeEvent"> <%: Html.RadioButton("A1", "1", ViewData["IsSelected"] == "1", new { onclick = "document.getElementById('ChangeEvent').submit();" })%> Active <%: Html.RadioButton("A1", "2", ViewData["IsSelected"] == "2", new { onclick = "document.getElementById('ChangeEvent').submit();" })%> Not Active <%: Html.RadioButton("A1", "3", ViewData["IsSelected"] == "3", new { onclick = "document.getElementById('ChangeEvent').submit();" })%> All </form> Inside the code, Request.Form ["A1"] is used to get the selected value ...
Enjoy! :)