Autopunch answer to matrix question from previous single answer question | XM Community
Skip to main content
Solved

Autopunch answer to matrix question from previous single answer question

  • January 10, 2024
  • 2 replies
  • 144 views

Forum|alt.badge.img+1

I have a project that I need to replace the old question (single row matrix table question) to a new one (multiple choice - single answer question). We don’t want to fully delete the old question as there are automations that are dependent on this. So, we wanted to simply copy the response from the new question and have it autocoded to the old one.

 

My challenge right now is I don’t know how to do this via javascript.

Best answer by ArunDubey

Hi Kenl,

I’m assuming your setup as:
 

if your both questions recode are same (single select answer options recode and grid scale options recode) and setup looks like this. Then you can keep both question on same page and hide the old question using JS. Please refer below code for hide and punch.

please note: read comment next to each code line for more clarity.


please replace QID33 with new question ID and QID34 with Old Question ID in below code.

	jQuery("#QID34").hide(); // hide Old question
jQuery("#NextButton").click(function(){
var inputX = jQuery("#QID33 input[type='radio']:checked").val(); // record the selected radio value
var clX= '.QR-QID34-1-' + inputX; // create selector for old question to punch the new question value
jQuery(clX).prop("checked", true); // punch old question
});

 

2 replies

ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • Answer
  • January 10, 2024

Hi Kenl,

I’m assuming your setup as:
 

if your both questions recode are same (single select answer options recode and grid scale options recode) and setup looks like this. Then you can keep both question on same page and hide the old question using JS. Please refer below code for hide and punch.

please note: read comment next to each code line for more clarity.


please replace QID33 with new question ID and QID34 with Old Question ID in below code.

	jQuery("#QID34").hide(); // hide Old question
jQuery("#NextButton").click(function(){
var inputX = jQuery("#QID33 input[type='radio']:checked").val(); // record the selected radio value
var clX= '.QR-QID34-1-' + inputX; // create selector for old question to punch the new question value
jQuery(clX).prop("checked", true); // punch old question
});

 


Forum|alt.badge.img+1
  • Author
  • 2 replies
  • January 11, 2024

Thank you @ArunDubey - this works perfectly!