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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:46:04+00:00 2026-06-05T20:46:04+00:00

I was wondering if someone could provide some insight to as why when I

  • 0

I was wondering if someone could provide some insight to as why when I click on the random form link below it doesn’t randomly load one of the listed forms. It works on jfiddle here:

http://jsfiddle.net/tUMBp/1/

Any help would be greatly appreciated. Thanks in advance.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script src="http://code.jquery.com/jquery-1.7.2.js" type="text/javascript"></script><!-- This calls the jquery library -->

<script type="text/javascript">
$(document).ready(function() {
    $('#randomForm').click(function() {
        var forms = $('#forms > form');
        forms.hide();
        forms.eq(Math.floor(Math.random() * forms.length)).show();
    });
});
</script>

<title>Untitled Document</title>
</head>

<body>

<div id="forms">
    <form style="display:none;">
        This is your training site1
    </form>
    <form style="display:none;"><!-- the second form -->
        This is your training site2
    </form>
    <form style="display:none;"><!-- the second form -->
        This is your training site3
    </form>

    <form style="display:none;"><!-- the second form -->
       This is your training site4
    </form>


</div>



<a href="#" id="randomForm">Show random form</a>​



</body>
</html>
  • 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-06-05T20:46:07+00:00Added an answer on June 5, 2026 at 8:46 pm

    The problem is your jquery code runs before any forms exist on the page. At that point, you cannot assign the click event to #randomForm (jQuery will try to, but since #randomForm does not exist yet, it will do nothing).

    Use the document.ready handler:

    <script type="text/javascript">
    $(document).ready(function(){
        $('#randomForm').click(function() {
            var forms = $('#forms > form');
            forms.hide();
            forms.eq(Math.floor(Math.random() * forms.length)).show();
        });​
    });​
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I was wondering if someone could provide a little help. I've been
I'm just wondering if someone could point out why one should use jQuery event
I was wondering if someone could provide me with an example of using setStyle
Wondering if someone could help with with some Spring.net IOC integration into a .aspx
was wondering if someone could help with this one. This is the first time
Was wondering if someone could assist with some Postgres. I have a table which
Wondering if someone could please explain the difference between these two queries and advise
Wondering if someone could help me. I have next to no knowledge with Ajax,
Just wondering if someone could help me with a very simple SQL query. I
Just wondering if someone could point me in the right direction of how to

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.