Qualtrics.SurveyEngine.addOnload(function()
{
var container_div = document.getElementById("container");
var dice_button = document.getElementById("dice_button");
var dice_container_div = document.getElementById("dice_container");
function randomIntFromInterval(min,max) {
return Math.floor(Math.random()*(max-min+1)+min);
}
function roll_dice(dice_button, container_div, dice_container_div){
dice_button.onclick = function(){
var outcome = randomIntFromInterval(1,6);
var dice_pic_id = "dice_" + String(outcome) + ".jpeg";
var dice_link = "https://www.sas.upenn.edu/~jdorsett/experiment_pics/hannah/" + dice_pic_id;
var dice_pic = document.createElement("img");
dice_button.setAttribute("disabled", "disabled");
dice_pic.setAttribute('src', dice_link)
dice_pic.setAttribute('height', '300px');
dice_pic.setAttribute('width', '300px');
dice_container_div.appendChild(dice_pic);
container_div.style.display = 'none';
}
}
roll_dice(dice_button, container_div, dice_container_div);
});Same JS code can't be run twice on Qualtrics survey
Qualtrics.SurveyEngine.addOnload(function()
{
var container_div = document.getElementById("container");
var dice_button = document.getElementById("dice_button");
var dice_container_div = document.getElementById("dice_container");
function randomIntFromInterval(min,max) {
return Math.floor(Math.random()*(max-min+1)+min);
}
function roll_dice(dice_button, container_div, dice_container_div){
dice_button.onclick = function(){
var outcome = randomIntFromInterval(1,6);
var dice_pic_id = "dice_" + String(outcome) + ".jpeg";
var dice_link = "https://www.sas.upenn.edu/~jdorsett/experiment_pics/hannah/" + dice_pic_id;
var dice_pic = document.createElement("img");
dice_button.setAttribute("disabled", "disabled");
dice_pic.setAttribute('src', dice_link)
dice_pic.setAttribute('height', '300px');
dice_pic.setAttribute('width', '300px');
dice_container_div.appendChild(dice_pic);
container_div.style.display = 'none';
}
}
roll_dice(dice_button, container_div, dice_container_div);
});Best answer by RDurant
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.
