Javascript to gray out a textbox when a checkbox is marked?

Does anyone know of a script that will make a textbox so it can’t be typed in once the corresponding checkbox is marked? (there are multipe on the same page)

The basic idea is: document.myForm.myField.disabled = true;

If there are multiple, make sure their names are different.

Hi John, does this do what you need?

http://sandbox.windebank.com.au/DisableTextBox

Regards,
Jordan

If you want to grey out, u can use the above one:
document.myForm.myField.disabled = true;

if you want to show as normal one and want to restrict the user to add text:
document.myForm.myField.readOnly = true;

hope this helps…!

thnx,
krishna

Thanks for the help. I’m using this code but for some reason when I click the box, CLOSED shows up in the textbox and makes it uneditable, but it isn’t inserting ‘CLOSED’ into the database. Whenever I enter text in the box it’s saved.

function disableTextbox(checkbox, textbox) {
	var txt = document.getElementById(textbox);
	var chk = document.getElementById(checkbox);

	if (chk.checked == true) {
		txt.value = 'CLOSED';
		txt.disabled = true;
	} else if (chk.checked == false) {
		txt.disabled = false;
	}
}

Any ideas?