PDA

View Full Version : disabling radio buttons and checkboxes in netscape



scripter
Nov 13th, 2002, 10:28 AM
Hi,

I would like to disable radio buttons and checkboxes in a page.

disabled="true" works only in IE. I want somehting similiar to that for Netscape. Any work around will do which will disable the radio buttons and checkbox.

Thanx in advance

Roy Sinclair
Nov 13th, 2002, 04:48 PM
This sample page should get you started:

BTW, you should say NS4 when you mean that decrepit antique that is Netscape 4. Saying just NS would refer to the current version of Netscape which does support the disabled property for form fields.



<html>
<head>
<script>
function disableField(myField)
{
myField.disabled = true
return true
}
function enableField(myField)
{
myField.disabled = false
return true
}
function onfocusField(myField)
{
if (myField.disabled)
{
myField.blur()
return false
}
return true;
}
// The above functions are generic, the following function is specific to this page
function toggleFields(myField)
{
if (myField.checked)
{
disableField(document.forms["example1"].text1)
disableField(document.forms["example1"].checkbox1)
disableField(document.forms["example1"].select1)
}
else
{
enableField(document.forms["example1"].text1)
enableField(document.forms["example1"].checkbox1)
enableField(document.forms["example1"].select1)
}
document.forms["example1"].text1
}
</script>
</head>
<body>
<form name="example1">
Disable Fields: <input type="checkbox" name="control1" onclick="toggleFields(this)" checked="checked">
<br>
Text Field: <input type="text" name="text1" onfocus="return onfocusField(this)">
<br>
Check box: <input type="checkbox" name="checkbox1" onfocus="return onfocusField(this)" onclick="return onfocusField(this)">
<br>
Select: <select name="select1" onfocus="return onfocusField(this)">
<option></option>
</select>
</form>
<script>
disableField(document.forms["example1"].text1)
disableField(document.forms["example1"].checkbox1)
disableField(document.forms["example1"].select1)
</script>
</body>
</html>