Entry
How do I disable a SELECT element?
May 2nd, 2000 07:22
Martin Honnen,
If you want to do it statically you need to use
<SELECT ONFOCUS="this.blur()" ...>
for NN3/4 which don't support the HTML 4.0 DISABLED attribute and you
can use
<SELECT DISABLED ...>
for IE4+ and NN6.
To use both together:
<SELECT DISABLED
ONFOCUS="if (!document.all && !document.getElementById)
this.blur();"
>
If you want to dynamically disable/enable a SELECT use
<HTML>
<HEAD>
<SCRIPT>
function skip () { this.blur(); }
function toggleSelect (select) {
if (!select.disabled) {
select.disabled = true;
if (!document.all && !document.getElementById) {
select.oldOnFocus =
select.onfocus ? select.onfocus : null;
select.onfocus = skip;
}
}
else {
select.disabled = false;
if (!document.all && !document.getElementById) {
select.onfocus = select.oldOnFocus;
}
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<SELECT NAME="aSelect">
<OPTION>Kibology
<OPTION>Xibology
</SELECT>
<INPUT TYPE="button" VALUE="toggle select"
ONCLICK="toggleSelect(this.form.aSelect);"
>
</FORM>
</BODY>
</HTML>