Click to See Complete Forum and Search --> : Disabling a Button in Netscape
anil_jog
12-20-2003, 02:30 AM
How to disable a button in Netscape.
I know we can use document.frmName.ButtonName.disabled=true in case of Internet Explorer. But , this won't work in Netscape.
If any one knows about this ,Please tell me How to achive this.
Thanks & Regards
Anil
Pittimann
12-20-2003, 03:02 AM
Hi!
Assuming you are able to perform a browser check and use the disabled=true for browsers which understand this, you can use something like the following (in this example clicking "disable Button 2" assigns a class name to button2 and when button2 is clicked, there will be a check, whether button2 has that class name - if not, the alert will pop up; you could as well play with a variable instead or simply change the value of button2):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style type="text/css">
.disabledButton{
color:red;
}
</style>
<script language="JavaScript" type="text/javascript">
<!--
function disableButton2(){
if (document.myForm.button1.value=="disable Button 2"){
document.myForm.button2.className="disabledButton";
document.myForm.button1.value="enable Button 2"
}
else{
document.myForm.button2.className="";
document.myForm.button1.value="disable Button 2"
}
}
function amIdisabled(){
if (document.myForm.button2.className!="disabledButton")
alert('Button enabled');//what to do when button is enabled
}
//-->
</script>
</head>
<body>
<form name="myForm">
<input type="button" onclick="disableButton2()" name="button1" value="disable Button 2">
<br>
<input type="button" onClick="amIdisabled()" name="button2" value="Button 2">
</body>
</html>
I usually just set the value of button2 to "" (in older NS versions it will be more clear for the user, that the button is not available for starting some action on click...
Cheers - Pit