I have two surveys: Survey 1 and Survey 2. In survey 1, I have a “Text Entry” field where the participants can enter multiple lines and it will be displayed in Survey 2. I used JS and Query String to pass the data from survey 1 to survey 2.
Piped text value of the text entry field in survey 1: ${q://QID142/ChoiceTextEntryValue}
Imbedded data in survey 2: MM_Text
My JS code is given below. It is added to the last question of Survey 1.
jQuery("#NextButton").on('click', function() {
var MM_Val= "${q://QID141/SelectedChoicesRecode}";
var MM_Text= "${q://QID142/ChoiceTextEntryValue}";
var fullURL = 'Survey 2 link?'
+ 'MM_Val=' + MM_Val
+ '&MM_Text=' + MM_Text;
var link1 = window.open(fullURL, '_parent');
});
The code works fine and trigger survey 2 at the end of survey 1, as long as a participant do not use ENTER while writing in the Text Entry field of Survey 1. It accepts alpha numeric values, emojis, SPACE everything, except for ENTER. If someone writes a paragraph using ENTER instead of SPACE, the survey ends at the THANK YOU page of survey 1 and does not trigger Survey 2. How do I solve this issue?
Best answer by Nam Nguyen
@MM77_C URLs typically do not support line breaks, so if the text entered in the "Text Entry" field in Survey 1 contains line breaks, it can break the URL and prevent it from working as expected. More than that, everytime you pull "${q://QID142/ChoiceTextEntryValue}" with a line break it break the JS also. So you should encode the line break where it got capture in QID142 (i.e get the input field value when next button press)so that it can be safe to be handle with JS and attached properly
Here I encode it with URIComponent but also have to change the %0A to <br> because when you send it through URL It got automatically decode
@MM77_C URLs typically do not support line breaks, so if the text entered in the "Text Entry" field in Survey 1 contains line breaks, it can break the URL and prevent it from working as expected. More than that, everytime you pull "${q://QID142/ChoiceTextEntryValue}" with a line break it break the JS also. So you should encode the line break where it got capture in QID142 (i.e get the input field value when next button press)so that it can be safe to be handle with JS and attached properly
Here I encode it with URIComponent but also have to change the %0A to <br> because when you send it through URL It got automatically decode
@MM77_C URLs typically do not support line breaks, so if the text entered in the "Text Entry" field in Survey 1 contains line breaks, it can break the URL and prevent it from working as expected. More than that, everytime you pull "${q://QID142/ChoiceTextEntryValue}" with a line break it break the JS also. So you should encode the line break where it got capture in QID142 (i.e get the input field value when next button press)so that it can be safe to be handle with JS and attached properly
Here I encode it with URIComponent but also have to change the %0A to <br> because when you send it through URL It got automatically decode
Survey 2 has the embedded data MM_Text in the survey flow and it is attached to Q1 (Your response from Survey 1 is: "${e://Field/MM_Text}") of survey 2. The variable MM_Text is only an embedded data that gets its value from Survey 2 URL as mentioned above. It does not appear on the user interface.
Same Question about the 3rd one. Where to add it? Q1 of Survey 2 JS?
@MM77_C I thought you know coding, anyway. Like what I said, the 1st one is you have to get value where it’s been input, in the question with QID142. 2nd, when you attach the link, at your code now pull it from this embedded data instead of question response.(i.e change your code) 3rd one in the question where you want to pull in the data but you have to add a HTML element for the data to be pull in.
@MM77_C I thought you know coding, anyway. Like what I said, the 1st one is you have to get value where it’s been input, in the question with QID142. 2nd, when you attach the link, at your code now pull it from this embedded data instead of question response.(i.e change your code) 3rd one in the question where you want to pull in the data but you have to add a HTML element for the data to be pull in.
I don’t know coding. I did everything using ChatGPT.
That is why I took some time to get back to you. I had some issues with the placement of the codes you provided. Anyway it is done now. Thank you so much. My survey is working fine (there is a small issue but I am ignoring that for now).
Your assistance has been the most effective I've encountered on this platform—clear, concise, and successful on the first attempt. Thank you.