0

I want to call a function when checkbox value is true whether it is user input or retrieved from database. How to do it? My Code

function IsSubGroupNeeded() {
    var Subgrp = document.getElementById('myCheck').checked;

    if (Subgrp === true) {
        loadgrdSubgroupItem();
    }
};

From where should I call IsSubGroupNeeded function?

4
  • 2
    How is this different from your last question? Commented Feb 10, 2016 at 11:38
  • @Tushar it worked well with "onchange" in HTML. But I want without onchange. My last question answers solved my error and someone told to ask new one. Commented Feb 10, 2016 at 11:43
  • should i give you an answer using jquery @Mimi Commented Feb 10, 2016 at 11:45
  • Though I haven't used jquery yet but It's ok @Transformer Commented Feb 10, 2016 at 11:47

1 Answer 1

1

Here you go. for checkbox data coming from database on document.ready will do that for you, but for user input in an already loaded page you must go with either click or change and then check if its currently checked. the if(this.checked) will do that.

$(document).ready(function(){
    //on document load 
    if ($('input#mycheck').is(':checked')) {
        //cal the function
    }
});
// you have to do a check on when user input (click)
$("input#mycheck").change(function() {
    if(this.checked) {
        //call the function
    }
});

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.