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 click 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.
Using JavaScript change event for radio buttons First, register an event handler to the change event of the body . When a radio button is clicked, its change event is bubbled to the body. This technique is called event delegation. Then, show a corresponding message based on which radio button is selected.
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.
To define the click event handler for a button, add the android:onClick attribute to the <RadioButton> element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event.
There are two methods by which one can dynamically change the currently selected radio button by changing the checked property of the input type. Method 1: Using prop method: The input can be accessed and its property can be set by using the prop method.
$(':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();
}
});
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