Solved

multiple checkbox

Posted on 2011-03-18
2
315 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 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

635 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