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 7162981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:49:27+00:00 2026-05-28T13:49:27+00:00

var linksInCategory = document.id($(‘.CategoryTreeLabel’).href); var randomLinkArray = new Array(linksInCategory); //CategoryTreeLabel is the class all

  • 0
var linksInCategory = document.id($('.CategoryTreeLabel').href);
var randomLinkArray = new Array(linksInCategory);

//CategoryTreeLabel is the class all the anchor tags have that contain the href with the link to the page I want

     function goThere(link)
{
        var the_url = function pickRandomURL () {
            var random_url = randomLinkArray[Math.floor(Math.random()*randomLinkArray.length)];
            the_url = random_url;

        }
        var good_url = fixURL(the_url);
        var new_window = window.open(good_url,"new_window","menubar, resizeable. location, toolbar, status, scrollbars");
}


function fixURL(the_url) {
        var the_first_seven = the_url.substring(0,7);
        the_first_seven = the_first_seven.toLowerCase();
        if (the_first_seven != 'http://') 
        {
                the_url = "http://" + the_url;
        }
        return the_url;
}
</script>
</head>
<body>
<form name="the_form">

<input type="button" name="the_url" class="broadGroups" onClick="goThere(this)" src="the_url" value="Sports"></input>

<input type="button" name="the_url" class="broadGroups" onClick="goThere(this)"  src="the_url" value="Film"></input>

Basically I want to create an array of all the href links within the same tag as the class=”CategoryTreeLabel” Then I want to create a function goThere () that will open a new window with the URL of good_url. the_url needs to be randomly selected from the list of links we grabbed from the tags with a class of “CategoryTreeLabel” in the document.

Each of the buttons should call the goThere(this) function and pick a random URL out of the array we created, check if it has http:// (it always will redirect to a page without it, but i left it in for fun), then open that page

  • 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-28T13:49:28+00:00Added an answer on May 28, 2026 at 1:49 pm

    The return from the jQuery function is an array-like object, that is to say that it has a .length property and can be accessed with array-style [] bracket notation, so you don’t really need to create a separate array variable too.

    I notice that your buttons seem to be for different categories of links, like sports or film, so perhaps your intention is that the “Sports” button will select a random sports-related link while the “Film” button will select a random film-related link? If so you could have each button pass the category through to your goThere() function and select a random link from within that category. Something like this:

    function goThere(category)
    {
        // assume that the parameter is the class name for links
        // in the desired category
        var $myLinks = $("a." + category);
    
        // check if there are any matching links
        if ($myLinks.length === 0) {
            alert("Sorry, no links in the " + category + " category.");
            return;
        }
    
        var url = fixURL($myLinks[ Math.floor(Math.random()*$myLinks.length) ].href);
    
        var new_window = window.open(url,"new_window",
              "menubar, resizeable. location, toolbar, status, scrollbars");
    }
    

    You’d then set up your anchor tags to have class names with appropriate categories, something like this:

    <a class="sports" href="http://somesportssite.com">Super sports</a>
    <a class="film"   href="http://moviesRus.com">Movies</a>
    <a class="film"   href="http://animationplus.com">All about animation</a>
    <a class="sports" href="http://football.com">Football site</a>
    <a class="sports" href="http://skydiving.com">Let's jump!</a>
    

    And the associated buttons would be:

    <input type="button" value="Sports">
    <input type="button" value="Film">
    

    And you could set inline handlers like you had, onclick="sports", or you could do something like the following in your document.ready handler to set them all up with a single jQuery .click() call that assumes the appropriate classname/category is a lowercase version of the button label:

    $('input[type="button"]').click(function() {
        goThere(this.value.toLowerCase());
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var longitudeArray = new Array(<?php $result = count($longitudeArray); if ($result > 1){ echo implode(',',
var Stars = new Array(1,2,3,4,5,6,7,8,9,10); var StarsX = new Array(451,455,460,470,490,100,160,220,280,300); var StarsY = new
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
var insInvoice = new NpgsqlCommand( @INSERT INTO invoice_detail( invoice_id, invoice_detail_id, product_id, qty, price, amount)
var newUser = new tblUser() { Email = strEmail, Password = strPassword, DateBirth =
var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
var fsw = new FileSystemWatcher(sPath, *.PPF); fsw.NotifyFilter = NotifyFilters.FileName; fsw.IncludeSubdirectories = true; fsw.Created +=
var request = new Request({ method: 'get', url: 'onlinestatusoutput.html.php', onComplete:function(response) { $('ajax-content').get('tween', {property: 'opacity',
var input; // method 1 input = document.getElementById('address').value; alert(input) // method 2 eval('input =
var gaJsHost = ((https: == document.location.protocol) ? https://ssl. : http://www.); document.write(unescape(%3Cscript src=' + gaJsHost

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.