Click to See Complete Forum and Search --> : Need help making text fields read only unless a certain checkbox is checked


marshalwdr
10-14-2003, 03:42 PM
I have a checkbox and two text fields in a form. I don't want people to be able to fill out the text fields unless the checkbox is checked. I've been trying to set this up with a function using onFocus, onBlur events but I can't get it right. Any ideas? Thanks

Charles
10-14-2003, 03:52 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
textarea {display:block}
-->
</style>

<form action="">
<div>
<label><input type="checkbox" onclick="if (this.checked) {this.form.description.onfocus = function () {}; this.form.description.focus()} else {this.form.description.value = ''; this.form.description.onfocus = function () {this.blur()}}">Other</label>
<label>Description<textarea name="description" onfocus="this.blur()"></textarea></label>
<button type="submit">Submit</button>
</div>
</form>