Charles Okwuagwu
Charles Okwuagwu

Reputation: 10866

How to pass values to the onchecked event handler of iCheck

Please how may we pass values to the onChecked event handler of iCheck (ver 1.x)?

In my scenario, each radio-button has specific values which I need to pass to the checked event handler

How can I get iCheck to execute my function "score()" with receives values onChange, as in the sample below:

<input type="radio" class="checkbox-inline i-checks" name="grp_A" id="opt_1" onchange="score('0508AG08002', 1, 4.0)">
<input type="radio" class="checkbox-inline i-checks" name="grp_A" id="opt_2" onchange="score('05034etw034', 2, 5.0)">

<script>
    $(document).ready(function () {
        $('input').on('ifChecked', function (v) {
            console.log(v);
        });

        $('.i-checks').iCheck({
            radioClass: 'iradio_square-blue',
        });
    });

    function score(matric, qid, grade) {
        console.log(matric, qid, grade);
    }
</script>

Upvotes: 0

Views: 632

Answers (1)

Nikolay Ermakov
Nikolay Ermakov

Reputation: 5061

I would suggest you to move the data you want to pass to iCheck to a data attribute in your markup, e.g. to data-check. Then you could easily access that from ifChecked event like below. Check demo - Fiddle.

<input type="radio" class="..." name="grp_A" id="opt_1" data-check="'0508AG08002', 1, 4.0">
<input type="radio" class="..." name="grp_A" id="opt_2" data-check="'05034etw034', 2, 5.0">

$('input').on('ifChecked', function (v) {
    console.log( $(this).attr("data-check") );
});

Upvotes: 1

Related Questions