Jump to content

Page Redirection JS Help


Recommended Posts

Hello, 

I am creating a quiz application where I have two versions of the same quiz for my employees to take. I am trying to think of a way to redirect half of my employee table to quiz 1 and the other half to quiz 2.

My initial thought is to go off of Employee Number. If it is an odd number, they get quiz 1. If it is an even number, they get quiz 2. 

The employee number is 4 digits long. 

How would I go about finding if the last digit in the value is 1, 3, 5, 7, or 9?

<script>
if(Last Digit Of "[@authfield:employee_number]" == 1, 3, 5, 7, 9){
window.location = "http://www.mysite.com/admin.html";
}
else if (Last Digit Of "[@authfield:employee_number]" == 0, 2, 4, 6, 8){
window.location = "http://www.mysite.com/manager.html";
}
else{
window.location = "http://www.mysite.com/employee.html";
}
</script>

 

Link to comment
Share on other sites

Hello @kpcollier,

Please try the following solution:
 

<script>
  let lastDigit = [@authfield:Employee_number] % 10;

  if(lastDigit % 2 > 0) {
    window.location = "http://www.mysite.com/admin.html";
    }
  else if (lastDigit % 2 == 0) {
    window.location = "http://www.mysite.com/manager.html";
    }
</script>

So, the first step is to receive the remainder after dividing the employee number by 10. It returns the last digit of the employee number.

Then we can use the output. If the remainder after dividing the last digit by 2 gives 0 it is the even number, otherwise it is the odd number.

Hope, this works for your workflow. 

Link to comment
Share on other sites

Hey @CoopperBackpack,

Thank you for the reply! I have tried using this snippet on an HTML page, but I am getting an error. Uncaught SyntaxError: Unexpected number. When I open the page, nothing happens. I have tried logging out and logging back in on the page and received the same results. Any idea what this would be for?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...