Hi, I want to write some javascript: after 30 seconds, the screen shows a button, which needs to be clicked within 10 seconds. If it is clicked within 10 seconds, we show the message "Msg" and next button. If not, we show a "miss message" and automatically click the next button.
I guess this uses settimeout function and if logics. The "miss message" shows even if the button is clicked within 10 seconds. I used 'alert' to check, if the button is clicked, the variable is set to 1, but the "miss message" still shows. Why?
Here are my javascript:
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
jQuery("#Msg").hide();
jQuery("#MissMsg").hide();
jQuery("#SvcButton").hide();
jQuery("#NextButton").hide();
var x_val=0; // set this variable equal to 0
// After 30 seconds, show the button that needs to be clicked within 10 seconds
setTimeout(function(){
jQuery("#Button").show();
// if click the button, show the next button
jQuery('#Button').on('click', () => {
jQuery("#Msg").show();
jQuery("#NextButton").show();
var x_val=1; // set this variable equal to 1
});
// after ten seconds, hide timer, show MissServiceMessage
setTimeout(function(){
if (x_val==0){
jQuery("#MissMsg").show();
jQuery("#NextButton").click();
}
}, 10000);
}, 30000);
});
javascript if not click a button within certain time, show some message, settimeout and if logic
Best answer by AmaraW
Hi cm201623! We'd recommend checking out W3Schools as a great resource for getting started with custom code. We also have our pages on Adding Custom CSS and Adding JavaScript to help out! 😁
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.
