Re: DOCTYPE, javascript and Firefox

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

 



On Thu, 30 Oct 2008 15:45:55 +0200, Arno Kuhl wrote:

>[...]
>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?

You aren't doing it the DOM way, and telling FF3 to use HTML 4.01 (or
XHTML) means you should be doing it the DOM way. IE, Opera and Chrome
are being lax; FF isn't.

<input type='radio' name='autostart' value='0'
 onclick="document.getElementById('autostartlabel').className='disable';
 document.getElementById('startdate').disabled=true;" >No
<input type='radio' name='autostart' value='1'
 onclick="document.getElementById('autostartlabel').className='normal';
 document.getElementById('startdate').disabled=false;" >Yes
<label id='autostartlabel'>Startdate</label>
<input type='text' name='startdate' id='startdate' disabled='disabled' >

Better would be to throw the actions into a function, e.g.

<script type="text/javascript">
function setStartDateDisabled(asDisabled) {
	var autostartlabel = document.getElementById('autostartlabel');
	if (autostartlabel)
		autostartlabel.className = asDisabled ? 'disable' : 'normal';

	var startdate = document.getElementById('startdate');
	if (startdate)
		startdate.disabled = asDisabled;
}
</script>

<input type='radio' name='autostart' id='autostart_0' value='0'
 onclick="setStartDateDisabled(true);" >No
<input type='radio' name='autostart' id='autostart_1' value='1'
 onclick="setStartDateDisabled(false);" >Yes

PS: pick HTML4 or XHTML; your sample code shows the latter, the DOCTYPE
says the former.
--  
Ross McKay, Toronto, NSW Australia
"The lawn could stand another mowing; funny, I don't even care"
- Elvis Costello

-- 
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