Re: firefox and problems with getElementById
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: firefox and problems with getElementById

From: David Dorward <dorward@yahoo.com>
Date: Wed Nov 30 2005 - 20:03:50 CET

Andrea wrote:

> I am trying to alter css using javascript as well as use the innerHTML
> function. I have pasted below 3 forms that access getElementById in
> slightly different ways (I wanted to rule out that it was the method.)
> All 3 work fine on IE but only work momentarily on Firefox. For
> example, one form has text that changes from red to black when the user
> clicks the button. In IE it changes. In Firefox it changes for a
> split second then goes back to black.

> <form>
> <span id="change_color">
> This is black until user clicks the button.
> </span>
> <button
>
onclick='document.getElementById("change_color").style.color="red";'>Display

Internet Explorer has a bug. If you don't specify a type attribute for
button elements, then they default to type "submit". IE doesn't respect
this.

What is happening, is that Firefox is running the JavaScript, and then
submitting the form. Since you haven't specified an action (which is
_required_), Firefox performs error recovery and assumes you intended to
submit to the same URL. So you end up on the same page, but the state of
any JavaScript is reset.

-- 
David Dorward       <http://blog.dorward.me.uk/>   <http://dorward.me.uk/>
                     Home is where the ~/.bashrc is
Received on Sat Dec 3 04:33:53 2005