I intend to insert a random text into my question body. The random text could be either "positive" or "negative". Therefore,
(1) I create an embedded data named "tresult1" in the very beginning of the survey.
(2) I insert where I would like the random text inserted in the html view of the question body.
(3) add the follow javascript code in the question.
Qualtrics.SurveyEngine.addOnReady(function() {
var tresults = ["positive", "negative"];
var i = "${e://Field/tresult1}";
var tresult = tresults[i];
document.getElementById("random").innerHTML = tresult;
});
I found that the random text can be successfully inserted if I place only one of such questions on each page. But if I place more than one questions, then the second question and any questions following will not have the random text inserted. The only way to make the javascript work is to add page break. After add page break, each question will work as expected.
I would like to place two questions on each page. Does anyone know how to solve this problem? Thanks a lot!
Why javascript works in separate pages but doesn't work if I put the two questions in the same page?
Best answer by TomG
An element id has to be unique. To combine more than one on a page, use a class instead of an id.
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
