Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

multiple checkbox

Posted on 2011-03-18
2
Medium Priority
?
317 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
[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 20

Accepted Solution

by:
Proculopsis earned 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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