tags:

views:

372

answers:

2

i want to detect if the checkbox is set to true and then put some data into a textarea. any examples of this?

+5  A: 
$('input[type=checkbox]').change(function(){
   setMyTextArea(getMyMessage(this.checked));    
});

function setMyTextArea(text){
    $('#MyTextArea').val(text);    
}

function getMyMessage(checked){
    return (checked ? myCheckedMessage : myUncheckedMessage);
}
ChaosPandion
actually, this seems to work in firefox and chrome but not internet explorer.. any idea?
ooo
the messsage does eventually get sent to the textareas in IE after about 20 seconds where firefox is instant. any idea? also, IE when you uncheck doesn't seem to do anything
ooo
+3  A: 

Here's a quick and dirty example you could hook into an event handler:

Sample:

if ($("#myCheckbox").attr("checked")) {
   $("#myTextarea").text("some text");
}

Assume these controls are rendered:

<input type="checkbox" id="myCheckbox"/>
<textarea id="myTextarea"></textarea>
Kevin