Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery group of radio buttons .change method [duplicate]

I'm working with a form with a radio button which is part of a set of radios and just one can be selected at a time(no problem with the single selection). One of those radios must fire a code each time it's selected a diferent code when it is unselected (another radio is selected), im using .change method and it fires the code when you click it, but not when it looses the selection. What i want is to toggle or be able to know when it looses the selection.

I could do it adding code to the other radios .change method but there are many sets of radios and it would be painful, i'm looking for a one time config.

Edit

The markup is made of ASP MVC Razor engine like this:

@Html.RadioButtonFor(x => x.SomeModel, new { @class = "special-radio" })
@* Other radios but without the 'specia-radio' class *@

js:

// logging
$(function(){
  $('.special-radio').change(function(){
    console.log('change');
  });
});

The string change only appears when you click the 'special-radio' radio.

like image 976
loki Avatar asked Aug 31 '12 18:08

loki


1 Answers

There is no event triggered when a radio is unchecked, because it would be redundant. Try this instead:

http://jsfiddle.net/hmartiro/g4YqD/1/

It puts a change event on the set of radios and just fires one event if the selected radio is special and another event otherwise.

like image 113
Hayk Martiros Avatar answered Sep 28 '22 18:09

Hayk Martiros