Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1838208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:26:56+00:00 2026-05-17T06:26:56+00:00

I am trying to send the user to either google or yahoo depending on

  • 0

I am trying to send the user to either google or yahoo depending on which link they clicked, if they clicked the 1st one they will be taken to google, and if they clicked the seond they will be taken to yahoo.

So for the window.location function I am using a variable called website which I’m defining based on which link the user clicked. But it’s not working. The variable isn’t being recognized:

<script type="text/javascript">
    $(document).ready(function(){

        // define the variable website based on which link is clicked
        $('a').eq(0).click(function() {
            var website = 'http://google.com';
        });
        $('a').eq(1).click(function() {
            var website = 'http://yahoo.com';
        });

        $('a').click(function() {
            window.location = website;
        });

    });
</script>

<a href="#">Link 1</a>
<br />
<a href="#">Link 2</a>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:26:56+00:00Added an answer on May 17, 2026 at 6:26 am
    <script type="text/javascript">
    
        var _website = null;
    
        $(document).ready(function ()
        {
            $('a').eq(0).click(function ()
            {
                _website = 'http://google.com';
                Navigate();
            });
    
            $('a').eq(1).click(function ()
            {
                _website = 'http://yahoo.com';
                Navigate();
            });
        });
    
        function Navigate()
        {
            document.location = _website;
        }
    
    </script>
    
    <a id="link1" href="#">Link 1</a>
    <br />
    <a id="link2" href="#">Link 2</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a simple application which will send the user to
I am trying to create a login page that will send the user to
I am trying to send a new user name to add to one of
I am trying to send user to previous page history.go(-1). This works fine in
I`m trying to send simple html page with form data to user with GET,
I'm trying to insert user credentials into an HTTP request header which is then
I'm trying to send the user id (integer) from a view to the action.
In Web application, I'm trying to send mail to the user with an attachment,
I'm trying to have different html buttons that send user's to different sections of
am trying send an array to php file using $_POST ,still always getting an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.