Solved

multiple checkbox

Posted on 2011-03-18
2
310 Views
Last Modified: 2012-05-11
Dear EE,
I have 4 checkbox category
1. All Check
2. 20s age check
3. 30s age check
4. 40s age check
Inside <form> i have multiple checkboxes which I have distinguished by Id2,Id3 so on for 20s,30s respectively.

how can I checked 1. for all, 2. for 20s, 3. for 30s etc.

any sample code would be very much appreciated
Thankk you
0
Comment
Question by:saloj
2 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
ID: 35163678

Do you mean something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26895677.html</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

jQuery(document).ready( function() {

  $("input[id^=range-]").click( function() {
    var checked = $(this).get(0).checked;
    var selector = "input[class^=" + $(this).attr( "id" ) + "]"
    $(selector).each( function() {
      $(this).get(0).checked = checked;
    });
  });

});

</script>
</head>
<body>

Toggle All: <input id="range-" type="checkbox" />
Toggle 20s: <input id="range-20" class="range-" type="checkbox" />
Toggle 30s: <input id="range-30" class="range-" type="checkbox" />
Toggle 40s: <input id="range-40" class="range-" type="checkbox" />

<table id="my-table" border="1">
<tr><td> 20: <input class="range-20" type="checkbox" /> 30: <input class="range-30" type="checkbox" /> 40: <input class="range-40" type="checkbox" /> </td></tr>
<tr><td> 20: <input class="range-20" type="checkbox" /> 30: <input class="range-30" type="checkbox" /> 40: <input class="range-40" type="checkbox" /> </td></tr>
<tr><td> 20: <input class="range-20" type="checkbox" /> 30: <input class="range-30" type="checkbox" /> 40: <input class="range-40" type="checkbox" /> </td></tr>
<tr><td> 20: <input class="range-20" type="checkbox" /> 30: <input class="range-30" type="checkbox" /> 40: <input class="range-40" type="checkbox" /> </td></tr>
<tr><td> 20: <input class="range-20" type="checkbox" /> 30: <input class="range-30" type="checkbox" /> 40: <input class="range-40" type="checkbox" /> </td></tr>
</table>

</body>
</html>

Open in new window

0
 
LVL 3

Expert Comment

by:Manikandan1986
ID: 35163699
Please try this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
      <meta name="author" content="user_" />

      <title>Untitled 1</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
            <script type="text/javascript">
                  $(document).ready(function() {
                             
                              $("#all").click(
                                    function() {  
                                           var status = $(this).attr("checked");
                                           $('.all').each(function(index) {
                                                                     $(this).attr("checked", status);
                                                              });

                                         
                                     }
                              );
                             
                              $('.all').click(
                                    function() {  
                                    var status = true;
                                    $('.all').each(function(index) {
                                                                     if(status)
                                                                     {
                                                                           status = $(this).attr("checked");
                                                                     }
                                                       });
                                                       $("#all").attr("checked", status);
                                 }
                              );
                  });
            </script>
</head>

<body>

<input type="checkbox" name="all" id="all"/> All
<input type="checkbox" name="twenty" class="all"/>20s age
<input type="checkbox" name="thirty" class="all"/>30s age
<input type="checkbox" name="forty" class="all"/>40s age

</body>
</html>
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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now