Updates from March, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • ibnuyahya 2:28 pm on March 11, 2011 Permalink | Reply
    Tags: , select all   

    jQuery checkbox select all 

    You can simple use

    $('input[name=cbAll]').change(function(){
        $("input[name^=cbAction]").attr('checked', $(this).attr('checked'));
    });
    

    full sample

    <html>
        <head>
            <title>Jquery Checkbox Select All</title>
            <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
            <script type="text/javascript">
                $(document).ready(function(){
                    $('input[name=cbAll]').change(function(){
                        $("input[name^=cbAction]").attr('checked', $(this).attr('checked'));
                    });
                });
            </script>
        </head>
        <body>
    
            <input type="checkbox" name="cbAll" id="cbAll" /><label for="cbAll">Select All</label>
            <hr>
            <input type="checkbox" name="cbAction[]" value="on" /> checkbox 1<br/>
            <input type="checkbox" name="cbAction[]" value="on" /> checkbox 2<br/>
            <input type="checkbox" name="cbAction[]" value="on" /> checkbox 3<br/>
            <input type="checkbox" name="cbAction[]" value="on" /> checkbox 4<br/>
            <input type="checkbox" name="cbAction[]" value="on" /> checkbox 5<br/>
            <input type="checkbox" name="cbAction[]" value="on" /> checkbox 6<br/>
        </body>
    </html>
    
     
    • ibnuyahya 4:03 pm on January 29, 2011 Permalink | Reply
      Tags: array name,   

      jquery: input text with array name selector 

      we can use jQuery(‘[attribute^="value"]‘) to handle this problem. symbol ^ means you want to select elements that have the specified attribute with a value beginning exactly with a given string

      <html>
      	<head>
      		<title>jQuery array inputbox</title>
      		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script&gt;
              <script type="text/javascript">
                  $(document).ready(function(){
      				$('#btnSubmit').click(function(){
      					var display = '';
      					$("input[name^=txtList]").each(function() {
      						display += $(this).val() + ',';
      					});
      					$('#display').html(display);
      				});
                  });
              </script>
      	</head>
      	<body>
      		<input type="text" name="txtList[]" value="test 1" >
      		<input type="text" name="txtList[]" value="test 2" >
      		<input type="text" name="txtList[]" value="test 3" >
      		<input id="btnSubmit" type="submit" value="Test" />
      		<div id="display"></div>
      	</body>
      </html>
      

      details http://api.jquery.com/attribute-starts-with-selector/

       
    c
    compose new post
    j
    next post/next comment
    k
    previous post/previous comment
    r
    reply
    e
    edit
    o
    show/hide comments
    t
    go to top
    l
    go to login
    h
    show/hide help
    shift + esc
    cancel