iCheck library: value of selected radio button

Clive van Hilten picture Clive van Hilten · Sep 10, 2013 · Viewed 40.1k times · Source

jsFiddle here.

I'm a novice at Javascript and having trouble following the documentation at the iCheck page. I've followed the answer to what appears to be a very relevant StackOverflow question here but cannot get an alert to pop up displaying the value I've selected. Can anyone point me in the right direction, please?

HTML

<p>Are you sure you want to have your details removed from our marketing list?</p>
<div id="unsubscribe_radio">
    <ul>
        <li>
            <input type="radio" name="iCheck" value="yes">
            <label>Yes</label>
        </li>
        <li>
            <input type="radio" name="iCheck" value="no">
            <label>No</label>
        </li>
    </ul>
</div>

Javascript

$(document).ready(function () {
  $('input').iCheck({
     radioClass: 'iradio_flat-orange'
  });
  $("input:radio[name=iCheck]").click(function () {
     var value = $(this).val();
     alert("You clicked " + value);
  });
 });

Answer

Anton picture Anton · Sep 10, 2013

You must use iCheck like this

$(document).ready(function () {
    $('input[name="iCheck"]').on('ifClicked', function (event) {
        alert("You clicked " + this.value);
    });
    $('input').iCheck({
        radioClass: 'iradio_flat-orange'
    });
});

DEMO

Documentation