How to return to a field after an alert message | XM Community
Skip to main content

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);
}
}



});
```

image.pngThanks!
Erin

Be the first to reply!

Leave a Reply