Re: DOCTYPE, javascript and Firefox
- From: rosko@xxxxxxxxxxx (Ross McKay)
- Date: Fri, 31 Oct 2008 19:51:36 +1100
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
.
- References:
- DOCTYPE, javascript and Firefox
- From: "Arno Kuhl"
- DOCTYPE, javascript and Firefox
- Prev by Date: Re: [PHP] Sessions in object oriented code
- Next by Date: Re: [PHP] Mailing lists
- Previous by thread: RE: [PHP] DOCTYPE, javascript and Firefox
- Next by thread: [released] themeable canvas loader icon, with semi-transparency support
- Index(es):