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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:44:27+00:00 2026-06-17T18:44:27+00:00

I’m new to JS. I put document.getElementById in my JS and tried to put

  • 0

I’m new to JS. I put document.getElementById in my JS and tried to put that element into a p id, but when I click the button, nothing is showing up. What am I doing wrong here? Any help is greatly appreciated. Thank you!

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GRL Example</title>
<script>
function class_roll() {
    // Car Classes
    var classes = ["B", "A", "S", "R3", "R2", "R1"],
        classToUse = classes[Math.floor(Math.random() * classes.length)];
    var elemClass = document.getElementById("croll");
}

function track_roll() {
    // Tracks
    var tracks = ["Clear Springs Circuit", "Festival North Circuit", "Beaumont Circuit", "Finley Dam Circuit", "Gladstone Circuit", "Clifton Valley Trail", "Gladstone Trail"],
        trackToUse = tracks[Math.floor(Math.random() * tracks.length)];
    var elemTrack = document.getElementById("troll");
}
</script>
</head>

<body>

<p id="croll">Some text here</p>
    <button onclick="class_roll();">Class Roll</button>

<p id="troll">Some text here</p>
    <button onclick="track_troll;">Track Roll</button>

</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-17T18:44:29+00:00Added an answer on June 17, 2026 at 6:44 pm

    With First function

    function class_roll() {
        // Car Classes
        var classes = ["B", "A", "S", "R3", "R2", "R1"],
            classToUse = classes[Math.floor(Math.random() * classes.length)];
        var elemClass = document.getElementById("croll");
    }
    

    You are not performing any action therefore add some action which visible to you. Change it to.

    function class_roll() {
        // Car Classes
        var classes = ["B", "A", "S", "R3", "R2", "R1"],
            classToUse = classes[Math.floor(Math.random() * classes.length)];
        document.getElementById("croll").innerHTML = classToUse ;
    }
    

    With Second Function

    function track_roll() {
        // Tracks
        var tracks = ["Clear Springs Circuit", "Festival North Circuit", "Beaumont Circuit", "Finley Dam Circuit", "Gladstone Circuit", "Clifton Valley Trail", "Gladstone Trail"],
            trackToUse = tracks[Math.floor(Math.random() * tracks.length)];
        var elemTrack = document.getElementById("troll");
    }
    
    1. There is typo mistake in function name means name what you calling is different from definition name.
    2. document.getElementById("troll").innerHTML = trackToUse ;
      add this to see the selected option randomly.

    Here is repaired code for your assistance

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>GRL Example</title>
    
    </head>
    
    <body>
    
    <p id="croll">Some text here</p>
        <button onclick="class_roll();">Class Roll</button>
    
    <p id="troll">Some text here</p>
        <button onclick="track_roll();">Track Roll</button>
    
    </body>
    <script>
    function class_roll() {
        // Car Classes
        var classes = ["B", "A", "S", "R3", "R2", "R1"],
            classToUse = classes[Math.floor(Math.random() * classes.length)];
        document.getElementById("croll").innerHTML = classToUse ;
    }
    
    function track_roll() {
    
        var tracks = ['a' ,'a' ,'a' ,'a'];
            trackToUse = tracks[Math.floor(Math.random() * tracks.length)];
        document.getElementById("troll").innerHTML = trackToUse ;
    
    }
    </script>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace

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.