views:

680

answers:

1

How can I use jQuery to delete the text in the textarea that gets from the input_one when it not checked (one_1 one_3 one_4) ,and when it checked add it into textarea again?

The code is below:

<div id="input_one">
  <input type="checkbox" checked value="one">
  <input type="checkbox" checked value="one_1">
  <input type="checkbox" value="one_2">
  <input type="checkbox" checked value="one_3">
  <input type="checkbox" checked value="one_4">
</div>
<div id="input_two">
  <input type="checkbox" value="two_1">
  <input type="checkbox" checked value="two_2">
  <input type="checkbox" checked value="two_3">
  <input type="checkbox" checked value="two_4">
  <input type="checkbox" checked value="two_5">
</div>

<div id="t_area">
  <textarea id="get_checked">
    get from the two above checkbox if it checked such
    as "one_1 one_2 one_3 one_4 two_2 two_3 two_4 two_5"
  </textarea>
</div>
+1  A: 

Umn, this is very similar to this question:

http://stackoverflow.com/questions/786142/how-to-retrieve-checkboxes-values-in-jquery

altCognito
We meet again Mr. altCognito. I was going to link him to the same page that we both just answered earlier today, haha. We have no lives...
KyleFarris
So true, so true, our schedules must match or something. :)
altCognito
thanks!but I use you code in this linkbut why not this code don't work?<script type="text/javascript">function updateTextArea() {var allVals =[];var allids =[];$('#d :checked').each(function() {allids.push($(this).attr("id"));allVals.push($(this).val());});$('#t').val(allVals)}$('#tt').val(allids)}$(function() {$('#d input').click(updateTextArea);updateTextArea();});</script>