Solved

If no checkboxes on page are checked - clear value in textarea

Posted on 2011-09-06
2
153 Views
Last Modified: 2012-05-12
I need to loop through all checkboxes on page - if no are checked - then clear the value on a textfield/area, etc.? I am doing this on the check changed event for a checkbox
0
Comment
Question by:tbaseflug
2 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36491222
what is the question? show us your current code
0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 36495358
Very simple. Check below code. When you uncheck all checkbox the value in textarea fields get cleared.
You can test below code at

http://jsfiddle.net/Wc4NY/
<!DOCTYPE html>
<html>
<head>
<title>Kiran Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
 $('input:checkbox').click(function(){
   clear_textarea();
  });
});

function clear_textarea()
{
  var checkbox_flag = false;
  $('input:checkbox').each(function(){
    if($(this).is(':checked'))
      checkbox_flag = true;
  });
  
  if(!checkbox_flag)
    $('#mytextarea').html("");
}

</script>
</head>
<body>
  <form>
  <table>
    <tr>
      <td><input type="checkbox" checked></td>
      <td><input type="checkbox"></td>
      <td><input type="checkbox" checked></td>
      <td><input type="checkbox"></td>
      <td><input type="checkbox" checked></td>
    </tr>
    <tr>
      <td><input type="checkbox"></td>
      <td><input type="checkbox" checked></td>
      <td><input type="checkbox"></td>
      <td><input type="checkbox"></td>
      <td><input type="checkbox" checked></td>
    </tr>
    <tr>
      <td colspan="5">
        <textarea id="mytextarea" cols="30" rows="10">Sample Text Sample Text Sample Text</textarea>
      </td>
    </tr>
  </table>
</form>
</body>
</html>

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question