Hi Siuk,
I think this is what you want (it only works in IE like twist said):
<script language="Javascript">
function distextbox()
{
if (document.myform.CHB1.checked == true)
{
document.myform.T1.disabled = true;
document.myform.T1.style.backgroundColor = '#AAAAAA'
}
else
{
document.myform.T1.disabled = false;
document.myform.T1.style.backgroundColor = '#FFFFFF'
}
}
</script>
<form name="myform">
<input type="checkbox" onmouseup="javascript:distextbox()" id="CHB1" name="CHB1"><br>
<input type="text" id="T1" name="T1">
</form>
But you don't say if the textbox must be "clean/empty" if the checkbox is clicked. What if the users first fill the textbox and then click the checkbox?
In that case you can use this function:
<script language="Javascript">
function distextbox(FieldName)
{
if (document.myform.T1.value.length >= 1)
{
var FillEmpty = window.confirm('You choose to click the checkbox(and disable the textbox), but the Field "' +FieldName+ '" is filled.\n\nClick OK to empty the field automaticaly.\nClick Cancel keep the text');
if (FillEmpty)
{
{
if (document.myform.CHB1.checked == true)
{
document.myform.T1.disabled = true;
document.myform.T1.style.backgroundColor = '#AAAAAA'
document.myform.T1.value = ''
}
else
{
document.myform.T1.disabled = false;
document.myform.T1.style.backgroundColor = '#FFFFFF'
}
}
}
else
{
document.myform.CHB1.checked = false
}
}
else
{
if (document.myform.CHB1.checked == true)
{
document.myform.T1.disabled = true;
document.myform.T1.style.backgroundColor = '#AAAAAA'
}
else
{
document.myform.T1.disabled = false;
document.myform.T1.style.backgroundColor = '#FFFFFF'
}
}
}
</script>
<form name="myform">
<input type="checkbox" onclick="javascript:distextbox(document.myform.T1.name)" id="CHB1" name="CHB1"><br>
<input type="text" id="T1" name="T1">
</form>
Hope this helps,
Erik