Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Make One Checkbox Checks All The Others, that's a tutorials and not a question
adly3000
post Feb 7 2006, 11:12 AM
Post #1


Member [Level 1]
****

Group: Members
Posts: 58
Joined: 31-January 06
Member No.: 17,937



i learned the last night a new trick so i write it to you, may help you later:
1- that makes the upper checkbox check or uncheck all the other check boxes.
2- on check or uncheck the bg of that checkbox will change.
you may say it's easy but i used array name in the checkboxes whcih makes it difficult really ver difficult.(mmmm.. so ask why i choosed the hard way instead of naming my checkboxes box1,box2,...etc., cuz i use php code and i need to make an array for later use.)
and here's the code:
CODE
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function check()
{
    var length = document.form1.elements.length;
    if (document.form1.checkall.checked==1)
    {
        for (i=length-1; i>0; i--)
        {
            var e = document.form1.elements[i];
            if (e.type=='checkbox' && e.name.indexOf("dmsg") != -1)
            {
                e.checked=1;
                var msgno = 'msg'+i;
                changebg(e, msgno);
            }
        }
    }
    else
    {
        for (i=length-1; i>0; i--)
        {
            var e = document.form1.elements[i];
            if (e.type=='checkbox' && e.name.indexOf("dmsg") != -1)
            {
                e.checked=0;
                var msgno = 'msg'+i;
                changebg(e, msgno);
            }
        }
    }
}
function changebg(row, msgno)
{
    var checkrow = row;
    if (checkrow.checked == 1)
    {
        document.getElementById(msgno).bgColor="#66CCFF";
    }
    else
    {
        document.getElementById(msgno).bgColor="#FFFFFF";
    }
}
</script>
</head>

<body>
<form name="form1" method="post" action="">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="center"><input type="checkbox" name="checkall" value="checkbox" onClick="check();"></td>
      <td>&nbsp;</td>
    </tr>
    <?
    for ($x=10; $x>0; $x--)
    {
    ?>
    <tr id="msg<? echo $x; ?>">
      <td align="right" style="bgcolor: #ff0000"><input type="checkbox" name="dmsg[]" value="<? echo $x; ?>" onClick="changebg(this, 'msg<? echo $x; ?>');"></td>
      <td>box <? echo "$x"; ?></td>
    </tr>
    <?
    }
    ?>
  </table>
</form>
</body>
</html>

i hope that may help you in future.
Ahmed;
Go to the top of the page
 
+Quote Post
snlildude87
post Feb 16 2006, 02:30 AM
Post #2


Moderator
***************

Group: Members
Posts: 2,325
Joined: 8-March 05
From: Mawson, Antarctica
Member No.: 4,254



I've been wondering how this technique that I've seen in many forms is implemented, but I never bothered to research. Now I know!

Thanks for posting.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Cannot Access Checkbox(4)


 



- Lo-Fi Version Time is now: 8th October 2008 - 04:19 AM