Solved

Multiple checkbox select

Posted on 2006-11-07
8
217 Views
Last Modified: 2008-03-03
I would like to be able to let user's click on a select box and when that box is selected all other boxes on the page get selected as well.  Can anyone post a for loop that will make this happen?  My code is as follows:

<td width="50" align="center" valign="middle" bgcolor="#CCCCCC" class="message_subborder">
Select All</td><td width="10" align="left" valign="middle" bgcolor="#CCCCCC" class="message_subborder">
<input type="checkbox" name="delete">
</td></tr>
<%
Dim MyRecords

Set MyRecords = Server.CreateObject("ADODB.Connection")
ConnStr = "DRIVER={Microsoft Access Driver (*.mdb)};pwd=password;"
ConnStr = ConnStr & "DBQ=" & Server.MapPath("/dev/students.mdb")
MyRecords.Open(ConnStr)

SQLtemp = "SELECT tblMessages.intMessagesID AS MessageID, UserFrom.intAccessID AS UserFromID, UserTo.intAccessID AS UserToID, UserFrom.strFirstname, UserFrom.strLastname, "
SQLtemp = SQLtemp & "tblMessages.strEmailFrom, tblMessages.strEmailTo, tblMessages.strSubject, tblMessages.data_entry "
SQLtemp = SQLtemp & "FROM (tblAccess AS UserFrom INNER JOIN tblMessages ON tblMessages.strEmailFrom = UserFrom.strEmail) "
SQLtemp = SQLtemp & "INNER JOIN tblAccess AS UserTo ON tblMessages.strEmailTo = UserTo.strEmail "
SQLtemp = SQLtemp & "WHERE UserTo.intAccessID=" & Request.Cookies("intAccessID")

Set rs = MyRecords.Execute(SQLtemp)

column = 0 ' initialize counter
Do While Not rs.EOF
    Response.Write "<TR><td class=""message_subborder"" width=""100"" align=""center""><a href='/dev/their_profile.asp?UserFromID=" & rs("UserFromID") & "'> " &_
                "<IMG border=""0"" width=""100"" SRC='/dev/download_2.asp?UserFromID=" & rs("UserFromID") & "'></a></td>"
    Response.Write "<TD class=""message_subborder""><a href='/dev/showmessages.asp?MessageID=" & rs("MessageID") & "'>" & _
             RS("strFirstname") & " " & RS("strLastname") & "</a></TD>"  
     Response.Write "<td class=""message_subborder"">" & _
               RS("strSubject") & "</td>"
     Response.Write "<td class=""message_subborder"">" & _
               Rs("data_entry") & "</td>"
      Response.Write "<td align=""center"" class=""message_subborder"" colspan=""2"">" &_
                        "<input type=""checkbox"" name=""delete""></td>"
     Response.Write "</TR>" & vbNewLine
    RS.MoveNext
Loop

%>
0
Comment
Question by:pingeyeg
  • 4
  • 4
8 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 17892918
Add this script

<script>
function CheckAllDelete(oDeleteAll)
{
      var oDeletes = oDeleteAll.form.elements["delete"];
      var oDelete, i;

      for (i = 0 ; i < oDeletes.length ; i++)
      {
            oDelete = oDeletes[i];
            if (oDelete != oDeleteAll)
            {
                  oDelete.checked = oDeleteAll.checked;
            }
      }
}
</script>

in your head section and change

<td width="50" align="center" valign="middle" bgcolor="#CCCCCC" class="message_subborder">
Select All</td><td width="10" align="left" valign="middle" bgcolor="#CCCCCC" class="message_subborder">
<input type="checkbox" name="delete">
</td></tr>

to

<td width="50" align="center" valign="middle" bgcolor="#CCCCCC" class="message_subborder">
Select All</td><td width="10" align="left" valign="middle" bgcolor="#CCCCCC" class="message_subborder">
<input type="checkbox" name="delete" onclick="CheckAllDelete(this)">
</td></tr>
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 17892982
Works great on the first select box in the list, but any others that follow with not get checked.  Why would that be?
0
 
LVL 58

Expert Comment

by:amit_g
ID: 17893023
Should work for all of them. As far as I can see from the code, all are named as name="delete". Is that correct? You might want to post the HTML as seen by browser i.e. do view source in the browser and post that. If it is too long, just post few checkboxes.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:pingeyeg
ID: 17893064
Yes, each one is called delete, but yet only one gets checked when the master one is checked.
0
 
LVL 58

Expert Comment

by:amit_g
ID: 17893088
It should work as you can see for yourself

<html>
<head>
<title></title>
</head>
<body>

<script>
function CheckAllDelete(oDeleteAll)
{
      var oDeletes = oDeleteAll.form.elements["delete"];
      var oDelete, i;

      for (i = 0 ; i < oDeletes.length ; i++)
      {
            oDelete = oDeletes[i];
            if (oDelete != oDeleteAll)
            {
                  oDelete.checked = oDeleteAll.checked;
            }
      }
}
</script>

<form>
<input type="checkbox" name="delete" onclick="CheckAllDelete(this)">DeleteAll
<input type="checkbox" name="delete">Delete1
<input type="checkbox" name="delete">Delete2
<input type="checkbox" name="delete">Delete3
</from>

</body>
</html>

You will have to show us the HTML code as seen by the browser. There must be something else going on.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 17893133
Below is the html code:

<td width="50" align="center" valign="middle" bgcolor="#CCCCCC" class="message_subborder">
Select All</td><form action="" method="post"><td width="10" align="left" valign="middle" bgcolor="#CCCCCC" class="message_subborder">
<input type="checkbox" name="delete" onClick="CheckAllDelete(this)">
</td></tr>
<TR><td class="message_subborder" width="100" align="center"><a href='/dev/their_profile.asp?UserFromID=26'> <IMG border="0" width="100" SRC='/dev/download_2.asp?UserFromID=26'></a></td><TD class="message_subborder"><a href='/dev/showmessages.asp?MessageID=125'>Brannon Glover</a></TD><td class="message_subborder">test</td><td class="message_subborder">11/7/2006 3:34:23 PM</td><td align="center" class="message_subborder" colspan="2"><input type="checkbox" name="delete"></td></form></TR>
<TR><td class="message_subborder" width="100" align="center"><a href='/dev/their_profile.asp?UserFromID=26'> <IMG border="0" width="100" SRC='/dev/download_2.asp?UserFromID=26'></a></td><TD class="message_subborder"><a href='/dev/showmessages.asp?MessageID=126'>Brannon Glover</a></TD><td class="message_subborder">test</td><td class="message_subborder">11/7/2006 3:34:41 PM</td><td align="center" class="message_subborder" colspan="2"><input type="checkbox" name="delete"></td></form>
0
 
LVL 58

Expert Comment

by:amit_g
ID: 17893165
You are closing the form in every row. The </form> is there in each row. There should be only one </form> at then end of table. Also you should move the <form> (opening) outside of the table. Some browser don't do well for this kind of nesting.
0
 
LVL 1

Author Comment

by:pingeyeg
ID: 17893196
Man, I didn't even think about that.  Good catch!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question