1

I'm not sure if the change method is the correct to use. What i want is if the checkbox is clicked(checked) the html of the textarea is var two and if the checkbox is unchecked the html of the textarea is var one. How do i accomplish this?

<script type="text/javascript">
$(function() {


$('.image').change(function() {
var one='type information here';
var two='type url here';

if($('.information').html=='type information here') {
$('.information').html('type url here');
} else {
$('.information').html('type information here');
}

});



});
</script>


<input type="checkbox" class="image"/>
<textarea class="information">type information here</textarea>
1
  • You need to use jsfiddle. Make a jsfiddle with your example in it and then I will help you Commented Oct 2, 2011 at 20:38

1 Answer 1

3

Use .val() instead of .html(). Also, notice that you've forgot the parentheses in your if-condition.

$(function() {
    $('.image').change(function() {
        var one='type information here';
        var two='type url here';

        if($('.information').val() == one) {
            $('.information').val(two);
        } else {
            $('.information').val(one);
        }
    });
});
Sign up to request clarification or add additional context in comments.

3 Comments

Please mark the solution as the answer if it resolved your problem :)
@GrailsGuy There's a 15 minute timeout before an answer can be accepted.
My mistake! Just trying to help :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.