Radio Button Change Event
I am having 2 Radio Buttons.(For Ex : ID and Name)..
<%=Html.RadioButton("Emp","1")%>
<label>ID</label>
<%=Html.RadioButton("Emp","2")%>
<label>Name</label>
If i cli开发者_运维问答ck the Name,
<p>
<%:Html.LabelFor(m => m.MyDate)%>:
<%:Html.EditorFor(m => m.MyDate) %>
</p>
the above control should be visibled false..How to do this.
$(':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 other 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>
Under code behind use Request.Form["A1"] to get selected value...
Enjoy! :)
精彩评论