Run some jquery code when selecting radio button

I have these two switches:

Original <input id="video_is_derivative_false" name="video[is_derivative]" type="radio" value="false">
Derivative (<i>ex. remix, mashup etc...</i>) <input id="video_is_derivative_true" name="video[is_derivative]" type="radio" value="true">

and I want to call some jquery code when the "Produce" button is selected. How can i do this?

+3
source share
5 answers

Just attach a change event to it:

$('#video_is_derivative_true').change(function(){
 console.log("Selected");   
})

example: http://jsfiddle.net/niklasvh/cyADB/

+3
source
$("#video_is_derivative_true").click(function(){
alert("your code goes here");
});

Add onclick handler to input tag

You can also put something in a change handler

    $("#video_is_derivative_true").change(function(){
    if($(this).is(':checked')){
            alert("more code here");
        }

    });
+3
source

, , , . , , . :

$('#video_is_derivative_true').change(function() {
    if (this.checked) {
        alert('derivative checked!');
    }
});

+1
$('#video_is_derivative_true').bind('click change', function() {
    if (this.checked) {
        // derivative is checked
    }
});
0
$("#video_is_derivative_true").click(function(){ alert("your code goes here"); }); 
0

All Articles