Solved

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

Posted on 2011-09-06
2
152 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now