Solved
Java Script Question
Hello! For a project I'm working on, we need to run Java script on over 300 multiple choice questions (each of which is in a separate block). Is there a way to apply our script to multiple choice questions in bulk without copy and pasting our code into each individual question?
Current script:
Qualtrics.SurveyEngine.addOnReady(function(){
jQuery('body').keydown( function( event ) {
switch (event.which) {
case 49: // the 1 key
event.preventDefault();
jQuery(jQuery('span.LabelWrapper label')[0]).click()
jQuery('#NextButton').click();
break;
case 48: // the 0 key
event.preventDefault();
jQuery(jQuery('span.LabelWrapper label')[1]).click()
jQuery('#NextButton').click();
break;
default:
// don't do anything
break;
}
});
For more background on the purpose of our code etc, feel free to refer to this thread: https://www.qualtrics.com/community/discussion/1480/key-press-response-issue#latest
Thank you!
Best answer by TomG
@anm54267 - @AnthonyR means that since your script will run on every page, it should only apply on pages that have one and only one multiple choice question. It should also probably only apply if the MC question has two choices. So you should put your code inside if statements:
```
if(jQuery('.QuestionOuter.MC').length == 1) //one question is MC
if(jQuery('.QuestionOuter.MC li.Selection').length == 2) { //two MC choices (vertical)
...your code goes here...
}
}
```
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
