?
Solved

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

Posted on 2011-09-06
2
Medium Priority
?
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 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