check box question

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

How do I capture the click event of the check box so that every time the
box is ticked a text box is enabled, and every time the box is unticked
a text box is disabled?


Thanks,

Mike
 
Hi mike,
you have two ways to accomplish this task.

1. Use a checkbox server control and set the autopostback property to true.
This will postback the page each time you click the checkbox and in the
click event you verify the check status and enable or disable the textbox.

2. Use a checkbox html control in combination with javascript.

Hope this helps.

Stefano Mostarda
Rome Italy
 
This can easily be achieved with JavaScript, which I would recommend over
the postback method, to avoid making unnecessary server round-trips.

// Enable/Disable the textbox, when the checkbox is clicked
function ToggleTextBox(e)
{
var txtbox = document.forms[0].elements["txtbox"];
txtbox.disabled = (!e.checked);
}
</script>

<!-- Form Sample Code -->
<form>
<input name="chk" type="checkbox"
onClick="ToggleTextBox(this)">Test<br><br>
<input name="txtbox" type="text" size="50" value="blah">
</form>


Hope this helps,

Mun
 
Back
Top