Solved

Multiple checkbox select

Posted on 2006-11-07
8
215 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now