Here is the code that I'm applying, it does give an alert box but as soon as I click on ok rather than letting me edit the mistake it takes me to the next page. How do I stop redirection?
Qualtrics.SurveyEngine.addOnReady(function()
{
var that = this;
jQuery("#NextButton").hide();
jQuery("#NextButton").after('');
var txtEntry = jQuery("input[id*='QR~QID'][type='text']");
jQuery("#CustomNextButton").click(function() {
var v1 = parseInt(txtEntry.eq(0).val());
var v2 = parseInt(txtEntry.eq(1).val());
var v3 = parseInt(txtEntry.eq(2).val());
var v4 = parseInt(txtEntry.eq(3).val());
var v5 = parseInt(txtEntry.eq(4).val());
var v6 = parseInt(txtEntry.eq(5).val());
var v7 = parseInt(txtEntry.eq(6).val());
var v8 = parseInt(txtEntry.eq(7).val());
var v9 = parseInt(txtEntry.eq(8).val());
var vtot1 = v2 + v3 + v4 + v5 - v6;
var vtot2= v1 - vtot1;
if (vtot2 != v7)
{ alert("Please enter the correct figures, Balance at 31 december = Balance at 1 January - Leavers during the year (resignation, retrenchments, dismissed, retirements + Number of new joiners) ");}
else { that.clickNextButton();}
var per_staff= v8;
var temp_staff= v9;
var total_temp_per_staff = per_staff + temp_staff;
if (total_temp_per_staff != v7)
{ alert("Please enter the correct figures, Balance at 31 december = Permanent Staff + Temporary Staff ");
}
else { that.clickNextButton();}
});
});
How do i stay on the same page after clicking ok on the alert box using javascript?
Best answer by Eumetis
Thank you for your response🙂. I had tried this before and it hadn't worked. So I put all the ifs inside a main if condition and that worked
if (vtot2 != v7 || total_temp_per_staff != v7 || total != v7)
{
if(vtot2 != v7)
{alert("Please enter the correct figures, Balance at 31 december = Balance at 1 January - Leavers during the year (resignation, retrenchments, dismissed, retirements + Number of new joiners) ");}
if(total_temp_per_staff != v7)
{alert("Please enter the correct figures, Balance at 31 december = Permanent Staff + Temporary Staff ");}
if( total != v7)
{alert("Please enter the correct figures, Balance at 31 december = No of male employees + No of female employees ");}
}
else { that.clickNextButton();}
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.
