SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    controling group of checkbox with javascript

    hello,

    Im not a javascript expert so Im hoping someone here can help me figure out what i need done..
    I found a javascript tutorial that im trying to implement in my script.

    What works: limiting the amount of check box a user can check.

    not sure how to do the following: create the javascript specific to the group of check box offered to the user so that the java script doesn't affect other checkboxs in the script.

    HTML Code:
    <input id="vehicle" type="checkbox" name="vehicle[]" value="Bike">bike <br />
    <input id="vehicle" type="checkbox" name="vehicle[]" value="Car">car <br />
    <input id="vehicle" type="checkbox" name="vehicle[]" value="van"> Van <br />
    HTML Code:
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    
    	<script type="text/javascript" > 
              jQuery(function(){
              var max = 3;
              var checkboxes = $('input[type="checkbox"]');
                           
              checkboxes.change(function(){
              var current = checkboxes.filter(':checked').length;
            checkboxes.filter(':not(:checked)').prop('disabled', current >= max);
        });
    });
    	</script>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You can use something like the below snippet which will restrict the code to only inputs beginning with the name of vehicle.

    Code JavaScript:
    $('input[name^="vehicle"]');

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chris.upjohn View Post
    You can use something like the below snippet which will restrict the code to only inputs beginning with the name of vehicle.

    Code JavaScript:
    $('input[name^="vehicle"]');

    thanks friend.. it worked...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •