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')r0]).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!
Page 1 / 1
Hello @anm54267 ,
You can place your code in "look and feel"-> "Advanced"("General")->"header(edit)"->"source(<>)", by doing so the script will run at each page
You can place your code in "look and feel"-> "Advanced"("General")->"header(edit)"->"source(<>)", by doing so the script will run at each page
> @Shashi said:
> Hello @anm54267 ,
>
> You can place your code in "look and feel"-> "Advanced"("General")->"header(edit)"->"source(<>)", by doing so the script will run at each page
In addition to this you will need to check that the question on page is multiple choice.
> Hello @anm54267 ,
>
> You can place your code in "look and feel"-> "Advanced"("General")->"header(edit)"->"source(<>)", by doing so the script will run at each page
In addition to this you will need to check that the question on page is multiple choice.
@AnthonyR Can you elaborate on this?
> @AnthonyR said:
> > @Shashi said:
> > Hello @anm54267 ,
> >
> > You can place your code in "look and feel"-> "Advanced"("General")->"header(edit)"->"source(<>)", by doing so the script will run at each page
>
> In addition to this you will need to check that the question on page is multiple choice.
> @AnthonyR said:
> > @Shashi said:
> > Hello @anm54267 ,
> >
> > You can place your code in "look and feel"-> "Advanced"("General")->"header(edit)"->"source(<>)", by doing so the script will run at each page
>
> In addition to this you will need to check that the question on page is multiple choice.
@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...
}
}
```
```
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...
}
}
```
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.