Jul 24, 2008

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

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

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.
Confirm Code:

Recent Queries:-
  1. html make one checkbox check other checkboxes - 2.16 hr back. (1)
  2. javascript checkbox check one uncheck other - 5.92 hr back. (1)
  3. if one checkbox is checked, all others cannot be checked - 52.68 hr back. (1)
  4. checkboxes in a form javascript - 69.25 hr back. (1)
  5. php checkbox check all array - 145.42 hr back. (1)
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

Searching Video's for make, checkbox, checks, tutorials
advertisement



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



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
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