samedi 20 janvier 2018

Reset(uncheck) a singular checkbox automatically after it is checked in Javascript

I am trying to add functionality to a checkbox so that when it is checked, it performs a function and then unchecks itself. I only need the function to run once when it is clicked, but if it triggers again on uncheck that is fine. The checkbox is part of a table in a Qualtrics (web surveying platform).

the JavaScript is interwoven with Qualtrics' javascript interface but the trigger event goes something like this. Note: I haven't posted the full code because not all of it is mine and a lot of it is not relevant to the question.

Qualtrics.SurveyEngine.addOnReady(function()
{
this.questionclick = function(event,element){
    if(element.type=='checkbox'){
        var chkChoice = element.id.split('~');

        if (chkChoice[3]==1){
            var chkChoice = element.id.split('~');

            do something
            clear/uncheck the element we just clicked using the following 
            method

            document.getElementById("QR~1_QID69#6~1~3").checked=false;
        }
      }
}
});

I don't know a whole lot about JavaScript or Qualtrics but if I had to guess its got something to do with the fact that I'm trying to clear the element in which the event was called. If I try to clear another checkbox in that row it will clear it fine so I'm just not sure where to go from here. Do I need a different method to clear the box or should I try calling it by other means or elsewhere in the code.




Aucun commentaire:

Enregistrer un commentaire