Re: DOCTYPE, javascript and Firefox

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 30, 2008 at 9:45 AM, Arno Kuhl <akuhl@xxxxxxxxxxxx> wrote:
> I came across an odd thing with DOCTYPE, javascript and Firefox 3 that has
> me stumped. Not exactly a php issue but hoping someone else on the list has
> seen this before. (At least the script is php, hope that counts)
>
> I have the following code in my header script:
>
> echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
> \"http://www.w3.org/TR/html4/loose.dtd\";>\n";
>
>
> Elsewhere I have (simplified):
>
> echo "<input type='radio' name='autostart' value='0'"
>        ."onclick=\"autostartlabel.className='disable';"
>        ."article.startdate.disabled=true;\" />No"
>    ."<input type='radio' name='autostart' value='1'"
>        ."onclick=\"autostartlabel.className='normal';"
>        ."article.startdate.disabled=false;\" />"Yes";
> ...
> echo "<label id='autostartlabel'>Startdate"
>    ."<input type='text' name='startdate' id='startdate' disabled=true />"
>    ."</label>";
>
>
> It's simply 2 radio buttons and if "yes" is clicked related form fields are
> enabled, if "no" is clicked they're disabled.
>
> This code works fine in IE, Opera and Chrome, but gives a javascript error
> in FF when I click the radio button: "autostartlabel is not defined".
> However if I comment out the DOCTYPE line in the header it works fine in all
> browsers including FF. (Took ages to narrow it down to the DOCTYPE.) Does
> anyone know why, and how to fix it?
>
> Cheers
> Arno

The pragmatic approach says that you've already fixed it: just leave
the DOCTYPE out. :-)

I'm not sure what yours should be, but based on the snippet of HTML
you posted, yours should not be HTML 4.01. Since you are closing the
<input/> tags, you should probably be using one of the XHTML DOCTYPEs
(as long as the rest of your markup is consistent). I'm not sure that
would "fix" your issue, though.

As for why your page does that, I'm not really sure. If you leave the
DOCTYPE off the the browser will select the DOCTYPE it wants to use.
Perhaps since you declared the document to be HTML 4.01 Transitional,
Firefox is applying JavaScript rules where you can't refer to an
element in script simply using its ID attribute. You usually have to
use something like:

 document.getElementById('autostartlabel').className = 'disable';

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux