Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
How to make a link / button redirect to a different address based on which user clicks it

To make it simple, i have a menu that contains the items "W", "X", "Y" and "Z". Each item redirects to a different page on the website, regardless of the user. But i want item "Z" specifically to redirect to a different page depending on the user. For example, if user "1" clicks on "Z", then he will be redirected to the page example.com/z1. If it is user "2" who clicks on "Z", then he will be redirected to example.com/z2. And so forth.

Something like:

  • if user = user1, then button_Z = <p><a href="http://reddit.com/">Z</a></p>

  • if user = user2, then button_Z = <p><a href="http://youtube.com/">Z</a></p>

User1 is redirected to reddit, while user2 is redirected to YouTube.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It looks like you're wanting to do some pretty simple string concatenation in the url. Here's a simple example that show what it sounds like you're trying to achieve. Most likely you're going to want to get these variables out of the global scope and accept them as parameters for your functions or use some sort of state management.

let user = ''

document.querySelector('#username').addEventListener('change',updateUser)

function updateUser(e) {
   user = e.target.value
}

document.querySelector('#dropdown').addEventListener('change',redirect)

function redirect(e) {
  const selection = e.target.value;
  
  if (selection === 'Z') {
    console.log(`mywebsite.com/${selection}${user}`)
    // window.location.replace(`mywebsite.com/${selection}${user}`)
  } else {
    console.log(`mywebsite.com/${selection}`)
    // window.location.replace(`mywebsite.com/${selection}`)
  }
}
<input id="username" />

<select id="dropdown">
  <option>W</option>
  <option>X</option>
  <option>Y</option>
  <option>Z</option>
</select>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!