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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:36:45+00:00 2026-06-18T03:36:45+00:00

My onclick event is firing even without a click. I’m not sure why? Below

  • 0

My onclick event is firing even without a click. I’m not sure why? Below is my code. The home panel should load first and when the user clicks the aboutButton they should be taken to the about panel.

JS Bin: http://jsbin.com/alebox/1/edit

<!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" />
<title>Untitled Document</title>
<script>

function myOnloadFunc() {

    var homePanel = document.getElementById("homePanel");
    var aboutPanel = document.getElementById("aboutPanel");
    var settingsPanel = document.getElementById("settingsPanel");
    var gamePanel = document.getElementById("gamePanel");
    var resultsPanel = document.getElementById("resultsPanel");

    // All panels in app
    var panels = [homePanel, aboutPanel, settingsPanel, gamePanel, resultsPanel];


    // Show selected panel and hide all other panels
    function showPanel(panel) {
        for (var i = 0; i < panels.length; i++) {
            if (panels[i] === panel) {
                // Show panel
                // this referred to global object, i.e. window
                panels[i].style.display = "block";
            } else {
                // Hide
                panels[i].style.display = "none";
            }
        }
    }

    showPanel(homePanel);

    // CODE THAT IS GIVING ME A PROBLEM /////////////////////////
    var aboutButton = document.getElementById("aboutButton");

    aboutButton.onclick = showPanel(aboutPanel);
    // CODE THAT IS GIVING ME A PROBLEM /////////////////////////
}

window.onload = myOnloadFunc;
</script>

</head>

<body>
<!-- homePanel -->
<div class="panel" id="homePanel">
<div align="center">
<p><strong>Web App</strong></p>
<p><a id="playButton">Play</a> &nbsp;&nbsp;&nbsp; <a id="aboutButton">About</a></p>
</div>
</div>

<!-- aboutPanel -->
<div class="panel" id="aboutPanel">
About panel
</div>

<!-- settingsPanel -->
<div class="panel" id="settingsPanel">
Settings panel
</div>

<!-- gamePanel -->
<div class="panel" id="gamePanel">
Game panel
</div>

<!-- resultsPanel -->
<div class="panel" id="resultsPanel">
Results panel
</div>
</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-18T03:36:46+00:00Added an answer on June 18, 2026 at 3:36 am

    It’s firing because you’re calling it right away!

    So you want:

    aboutButton.onclick = function(){showPanel(aboutPanel);};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JavaScript event onClick close window not firing after clicking and viewing PrettyPhoto image. HTML
I am not able to apply onclick event in global custom text field. This
This code is suppose to add an onClick event to each of the a
I have following code that adds dynamic LinkButton on the click event of a
I am attaching onclick event on dynamically created button but the event is not
Ok, simple question: <div onclick=javascript:manualToggle(this)> <span>Allowed to click</span> <span>Not allowed to click</span> <span>Allowed to
$(div#foobar).live('click', function() { }); $(window).hashchange(function() { }); How can I stop firing hashchange event
Possible Duplicate: How can I stop an onclick event from firing for parent element
I have this jQuery code: $('#SomeLink').onclick = function(event) { alert('test'); }; And this is
I have a onclick event that is like: public void OnMyButton_Click(object sender, EventArgs e)

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.