Is it possible to change the "Next" button to "Finish" based on embedded data? | XM Community
Skip to main content
Solved

Is it possible to change the "Next" button to "Finish" based on embedded data?

  • September 25, 2024
  • 5 replies
  • 75 views

Forum|alt.badge.img+5

Background: I took the info I found here: https://community.qualtrics.com/custom-code-12/is-it-possible-to-change-the-next-button-to-finish-based-on-embedded-data-18014?postid=41891#post41891 …

I have essentially two versions of a survey:

  1. Version 1: ends at Question 10 if ${e://Field/Acquisition} is blank
  2. Version 2: continues with Questions 11-20 if ${e://Field/Acquisition} is Yes

On Question 10, I added this JavaScript:

Qualtrics.SurveyEngine.addOnReady(function() {
if("${e://Field/Acquisition}" != "null"){
var newName = 'Submit'; //Update - New Next Button label
var lastLoopOnly = true; //Last loop only? Value doesn't matter to non-loops
//No changes below
if(!lastLoopOnly || "${lm://CurrentLoopNumber}" == "${lm://TotalLoops}") {
var nb = jQuery('#NextButton');
nb.val(newName);
nb.attr('title', newName);
}
}
});

I added this JavaScript because Version 1 should have a “Submit” button on the page showing Question 10 whereas Version 2 should have a “Next” button. 

Problem: Version 1 is showing “Submit” which is great -- but Version 2 is showing “Submit” too and it should show “Next”. 

What am I doing wrong? 

@Rfredman, tagging you as the post in the first line above is yours. 

Best answer by happychuck77

Thanks, @Shashi! I took your code and fed it into my good friend Google Gemini to also account for the fact that I realized I need to change the label if Acquisition=No too. For posterity’s sake, here is the final code that worked!:

Qualtrics.SurveyEngine.addOnReady(function() {
  if ("${e://Field/Acquisition}" === null || "${e://Field/Acquisition}" === "" || "${e://Field/Acquisition}" === "No") {
    jQuery('#NextButton').attr("title", "Submit").val("Submit");
  }
});

 

View original

5 replies

Shashi
Level 8 ●●●●●●●●
Forum|alt.badge.img+32
  • Level 8 ●●●●●●●●
  • 633 replies
  • September 26, 2024

If you don’t have loop and merge on Q10 block then following code should work for you:

if("${e://Field/Acquisition}"==""){
		jQuery('#NextButton').attr("title","Submit").val("Submit");
	}

 


Forum|alt.badge.img+5
  • Author
  • Level 2 ●●
  • 21 replies
  • Answer
  • September 26, 2024

Thanks, @Shashi! I took your code and fed it into my good friend Google Gemini to also account for the fact that I realized I need to change the label if Acquisition=No too. For posterity’s sake, here is the final code that worked!:

Qualtrics.SurveyEngine.addOnReady(function() {
  if ("${e://Field/Acquisition}" === null || "${e://Field/Acquisition}" === "" || "${e://Field/Acquisition}" === "No") {
    jQuery('#NextButton').attr("title", "Submit").val("Submit");
  }
});

 


Forum|alt.badge.img+5
  • Author
  • Level 2 ●●
  • 21 replies
  • November 8, 2024

@Shashi (or others), I just realized that the button correctly says ‘Submit’ in English as it should, but I also have a French Canadian version of the survey. Is it possible to modify the Javascript to have the button say ‘Submit’ in the English version but ‘Soumettre’ in the French Canadian version?  


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1091 replies
  • November 8, 2024

@happychuck77 Add a Q_Language embedded data at the beginning and listen to the value of it to change the JS. Check for the Language code here
https://www.qualtrics.com/support/survey-platform/survey-module/survey-tools/translate-survey/#AvailableLanguageCodes


Forum|alt.badge.img+5
  • Author
  • Level 2 ●●
  • 21 replies
  • November 8, 2024

Thank you, @Nam Nguyen ! 


Leave a Reply