Hello!
How are you?
I have some JavaScript code that is doing calculations. If the final value is negative, then an alert error message appears. But when I click on the "ok", it takes me to the next question, rather than giving me a chance to correct the error. How can I fix this, please?
Here is the code:
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
var yro1 = Qualtrics.SurveyEngine.getEmbeddedData("yro");
var yrotext = yro1.substring(0,3);
var msg = ' ';
console.log("text");
console.log(yrotext);
var yri1 = Qualtrics.SurveyEngine.getEmbeddedData("yri");
var yritext = yri1.substring(0,3);
console.log("in");
console.log(yritext);
if(yrotext!='Don' && yritext !='Don') {
var yro1 = parseInt(yro1);
console.log("year out");
console.log(yro1);
var yri1 = parseInt(yri1);
var yrdiff = yro1 - yri1;
console.log("yrdiff");
console.log(yrdiff);
if(yrdiff<0) {
msg='invalid dates';
alert(msg);
}
}
});
```
Thanks!
Erin
How to return to a field after an alert message
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.
