Can I display the same Checkbox more than once in a form? And force all to update?
Results 1 to 5 of 5

Thread: Can I display the same Checkbox more than once in a form? And force all to update?

  1. #1

    Can I display the same Checkbox more than once in a form? And force all to update?

    Is this a really bad idea? I want to display the same checkbox in several places in a form. the user can check it on/off at any of those locations. The checkboxes would all have the same variable but all the checkboxes would update their displays no matter where the user checks or unchecks them.

    If this is really bad practice, I know I could create an array instead, but I'd rather not if I can avoid it.

    If my single variable method is doable, does anyone have a script suggestion to force all the boxes to update?
    Connie G.

  2. #2
    Un Re Member cretaceous's Avatar
    Join Date
    Sep 2004
    Location
    London UK
    Posts
    943
    This bit of jquery javascript checks a set of checkboxes with one click
    Code:
    <script type="text/javascript">
    jQuery.fn.checkAll = function(name,flag){
    var selector = ':checkbox'+(name?'[@name='+name+']':'');
    $(selector,this).attr('checked',flag);
    }
    </script>
    
    the inputs
    <input type="button"  value="Select all " onclick="$('#formname').checkAll('', 1);"/>
    <input type="button" value="Deselect all" onclick="$('#formname').checkAll('', 0);"/>
    - should be easy to adapt

    You'd be better off with array based names - it won't validate for one

  3. #3
    Member
    Join Date
    Dec 2004
    Posts
    38
    no jquery needed.

    Code:
    function Check(chk)
        {
            if(document.smform.Check_All.checked){
            for (i = 0; i < chk.length; i++)
            chk[i].checked = true ;
            document.smform.Check_All.checked = true;
        }else{
    
            for (i = 0; i < chk.length; i++)
            chk[i].checked = false ;
            document.smform.Check_All.checked = false;
        }
    }
    JSfiddle http://jsfiddle.net/5JCMS/

  4. #4

    Thank you - noob needs a little more help please...

    Thank you for your answer. So in my <input> statement, how do I write the parameter for the onclick()? onclick='Check(???)';

    Thank you - I'm just figuring out javascript.

    C.G.

    Quote Originally Posted by bemore View Post
    no jquery needed.

    Code:
    function Check(chk)
        {
            if(document.smform.Check_All.checked){
            for (i = 0; i < chk.length; i++)
            chk[i].checked = true ;
            document.smform.Check_All.checked = true;
        }else{
    
            for (i = 0; i < chk.length; i++)
            chk[i].checked = false ;
            document.smform.Check_All.checked = false;
        }
    }
    JSfiddle http://jsfiddle.net/5JCMS/
    Connie G.

  5. #5
    Never mind, I just found the rest of the information at your link. Thanks.
    Connie G.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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