Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 click the Name,

<p>
   <%:Html.LabelFor(m => m.MyDate)%>:&nbsp;
   <%:Html.EditorFor(m => m.MyDate) %>
</p>

the above control should be visibled false..How to do this.

like image 671
RobinHood Avatar asked Nov 17 '10 08:11

RobinHood


People also ask

How do you change the event for a radio button?

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.

Does radio button have onChange?

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.

Can I use onClick in radio button?

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.

How can I change checked radio button in jQuery?

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.


1 Answers

$(':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();
    }
});
like image 135
Darin Dimitrov Avatar answered Sep 23 '22 22:09

Darin Dimitrov