jeudi 27 avril 2017

jquery checkbox is not working on single click

I am not sure what i am doing wrong but i have to changge a checkbox state on click of an image and its not working

I have a checkbox in a repeater controls whose attribute data-id-chk gets set from page behined

<asp:CheckBox ID="chk_QuizQuestionOptionGUID" runat="server" CssClass="QuestionFormRadioButton" data-id-chk="0" />

then there is a aspx wheere i am simplay calling the javascript function on click of an image. but i want to change checkbox state which is not getting changed.

function AddRemoveStyle(target) {
    try {

    var dataid = $(target).attr("data-id-img");

    var mychk = $('[data-id-chk="'+ dataid +'"]');

    var ckb = $(mychk[0]).is(':checked');
    if (!$(mychk[0]).is(':checked')) {
        $(mychk[0]).prop('checked', true);
    }
    else{           
        $(mychk[0]).prop('checked', false);
    }


    }
    catch (e) {
        // statements to handle any exceptions
        alert(e); // pass exception object to error handler
    }
}

</script>

here is the image to call the above method:

<a href="#" id="Photo4">
<div>
<div>
<asp:Label ID="lbl_QuizQuestionOptionGUID" runat="server" Visible="false" Text='<%#Eval("QuizQuestionOptionGUID")%>'></asp:Label>
<img id="img_Option" runat="server" src="/assets/images/null.gif" alt="null" onclick="AddRemoveStyle(this);" />                                                                                                 
</div>
</div>




Aucun commentaire:

Enregistrer un commentaire