Hi.

In March current year I started learning html, css, php, mysql, and a month ago started with Javascript. I have a webpage that I am working on to have practical tasks for finding solutions to them.

I have created a Javascript code that colores the rows of a table when the mouse is over them. The problem is that Javascript code is not working when the page is accessed through a link that sends variables by "_GET" method. You can check it on: http://soccerstatistics.eu/index.php (I need to tell that the Javascript code I added only on this page (index.php), for testing). But when I click in the page on "Full Time" that brings me to the same page (index.php): http://soccerstatistics.eu/index.php?season=2012-2013&&s_type=Over+2.5+Goals , the rows of the table are not changing the colors anymore. When I go back clicking on "Home", it works again.

Please help me to find a solution. The Javascript code is:

<script>
var rows = document.getElementById("leagues_stands").getElementsByTagName("tr");
for (var i = 0; i < rows.length; i++) {
  if(rows[i].className == "blue_odd") {
    rows[i].onmouseover = function() {
      this.style.backgroundColor = "#00AED1";
    };
    rows[i].onmouseout = function() {
      this.style.backgroundColor = "#CCFFFF";
    };
  }
  else if(rows[i].className == "blue_even") {
    rows[i].onmouseover = function() {
      this.style.backgroundColor = "#00AED1";
    };
    rows[i].onmouseout = function() {
      this.style.backgroundColor = "#9FEEEE";
    };
  }
}
</script>

Recommended Answers

All 2 Replies

On the index code you are applying a class to the tr elements:

Example:

tr class="blue_odd"

On the index page with the parameters in the URL you are applying the class to the td elements:

Example:

td id="xl_body" class="blue_odd"

You guys are amazing, finding solutions so fast! Thank you so much, JorgeM. Now I know what should be changed. Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.