Make One Checkbox Checks All The Others - that's a tutorials and not a question

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

Make One Checkbox Checks All The Others - that's a tutorials and not a question

adly3000
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;

 

 

 


Reply

snlildude87
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. unchecking all html checkbox - 1.36 hr back. (1)
  2. checkbox uncheck others function javascript - 4.88 hr back. (1)
  3. checkbox access tutorial checked - 7.66 hr back. (1)
  4. make the checkbox uncheck javascript - 72.02 hr back. (1)
  5. access checkbox chekcs also others - 80.10 hr back. (1)
  6. one checkbox checked others - 81.23 hr back. (1)
  7. java checkbox checked all and uncheck all - 93.58 hr back. (1)
  8. javascript "other checkbox" all - 101.28 hr back. (1)
  9. how to create check all function in javascript and jsp - 170.81 hr back. (1)
  10. checkbox checked=javascript - 179.19 hr back. (1)
  11. make checkbox checked php - 222.64 hr back. (1)
  12. to uncheck all the other checkboxes when a checkbox is checked - 247.14 hr back. (1)
  13. access one checkbox to check all - 256.92 hr back. (1)
  14. document.form1.elements[i].name.indexof - 265.62 hr back. (2)
Similar Topics

Keywords : make, checkbox, checks, tutorials

  1. Cannot Access Checkbox
    (4)
  2. Java Script Tutorials
    (3)
    This Is Java Script tutorial which is very neccessary for webdesgining so contrate and learn its
    nice and easy QUOTE Since the day Microsoft built support for JavaScript into Internet
    Explorer 3.0, Netscape's client-side language has become the de facto standard for enhancing web
    pages at the browser. In this full-length excerpt from Practical JavaScript Programming, author
    Reaz Hoque explains the basics of client-side scripting. He also gives you some neat scripts that
    can enhance your web pages, making them impressively interactive. Important code snippets ....
  3. Java Lab 01
    My first installment of Java tutorials (1)
    I have decided to come up with a series of Java tutorials teaching simple Java. This is my first
    chapter. For this chapter, I will be showing how to write a simple program that: 1. Pops up a
    JOptionPane, 2. Shows a message on the pane. Classes, Objects Java, as some of you might already
    know, is a/an (almost) completely object-orientated programming language (OOP). Some of the experts
    out there may argue that Java is fully object-orientated, but I don't think that is absolute.
    Some programmers consider Ruby to be fully OOP and Java to be almost fully OOP because ....

    1. Looking for make, checkbox, checks, tutorials

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for make, checkbox, checks, tutorials

*MORE FROM TRAP17.COM*
advertisement



Make One Checkbox Checks All The Others - that's a tutorials and not a question



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE