How to connect radioButton ( ) to call function when is checked?

Go To StackoverFlow.com

1

How to connect radioButton

<input type radio .. />

to call function when is checked ? I need to record value of that button when it is checked.

2012-04-04 07:44
by Damir


1

js:

<script>
function yourfunction()
{
    //function
}
</script>
<input id = "radio1" type = "radio" onclick = "yourfunction()" />

jQuery:

<script>
$( '#radio1' ).click(function(e)
{
    //function
});
</script>
<input id = "radio1" type = "radio" />

You can add condition to check if the radio is chcecked or not, would look like

if ($( '#radio' ).attr('checked') == 'true')
{
}
2012-04-04 07:49
by Milan Halada


2

as you can see in the fiddle

html:

<input type="radio" value="Test 1" /> Bullet 1 <br />
<input type="radio" value="Test 2" /> Bullet 2 <br />
<input type="radio" value="Test 3" /> Bullet 3 <br />
<input type="radio" value="Test 4" /> Bullet 4 <br />

js:

$(document).ready(function() {
    $("input").click(function() {
        if ($(this + ":checked")) {
            alert($(this).val());
        }
    });
});​
2012-04-04 07:57
by Frederiek
Ads