Search code examples
jqueryinputradio-button

JQuery: Get radio value and perform different operations


I have 2 radio inputs. How can I process jquery functions on a selected value on a onchange event?

<input value="radio_2way" name="IBE1$IBE_NurFlug1$flightIBE" id="IBE1_IBE_NurFlug1_radio_2way" checked="checked" type="radio">Hin- und Rückflug &nbsp;&nbsp;<input value="radio_1way" name="IBE1$IBE_NurFlug1$flightIBE" id="IBE1_IBE_NurFlug1_radio_1way" type="radio">Einfach

If the checked value is radio_1way do function1 and if it is radio_2way do function2.

thx a lot, greetings


Solution

  • Just attach a change event to the radio's

    $(document).ready(function(){
        $('input[id^="IBE1_IBE_NurFlug1"]').change(function(e){
           var $changed = $(e.target);
           alert($changed.val());
        });
    });
    

    check the jsFiddle: http://jsfiddle.net/BUgRV/