Simple javascript not working in Firefox

rypinbubs
rypinbubs used Ask the Experts™
on
Can anybody tell me why this simple example works fine in IE, Chrome, Safari, and Opera but not in FireFox?

Thanks!

HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication8.WebForm1" %>

<!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 runat="server">
    <title></title>
</head>
<body id="body">
<script type="text/javascript">
    function setHover(id, color) {
       if(id != "") {
         var buttonName = document.getElementById(id.id);
         buttonName.style.backgroundColor = color;
        }
    }
 </script>
    <form id="form1" runat="server">
    <div id ="test">
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

Open in new window


CodeBehind
public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Attributes.Add("onmouseover", "setHover(window.event.srcElement, 'Red');");
        }
    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
As far as I can read, FF doesn't use window.event. There is discussion of this here. However, why use Javascript just to change the backcolor of something? Why wouldn't you use the CSS pseudo-class :hover?
Commented:
You can try this one
Button1.Attributes.Add("onmouseover", "setHover(this, 'Red');")

"this" will pass the current button and you can get the id in javascript code.
i agree with kaufmed, this is a job for css not javascript.

Author

Commented:
I agree with kaufmed too, but unfortunately this is just a small part of a bigger problem.
Thanks for the help guys!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial