View Full Version : Disable if is checked
stevenoi
06-29-2009, 07:14 AM
Hi, I try to create a script that disable the textarea's named "dis" if "yes" from a radio box is checked. Hope you can help me.
Steven.
coothead
06-29-2009, 01:40 PM
Hi there stevenoi,
have a look at this example, it may suit your requirements...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title></title>
<style type="text/css">
.bg {
background-color:#d4d0c8;
}
</style>
<script type="text/javascript">
function mytest(){
test=true;
obj0=document.getElementById('r1');
obj1=document.getElementById('ta');
obj2=document.getElementById('lab1');
obj0.onclick=function() {
if(test==true) {
this.checked=true;
obj1.disabled=true;
obj1.className='bg';
obj2.firstChild.nodeValue=': enable';
test=false;
}
else {
this.checked=false;
obj1.disabled=false;
obj1.className='';
obj2.firstChild.nodeValue=': disable';
test=true;
}
}
}
if(window.addEventListener){
window.addEventListener('load',mytest,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',mytest);
}
}
</script>
</head>
<body>
<form action="#">
<div>
<textarea id="ta" rows="10" cols="30"></textarea>
<input id="r1" type="radio"><label id="lab1" for="r1">: disable</label>
</div>
</form>
</body>
</html>
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.