Solved

Multiple checkbox select

Posted on 2006-11-07
8
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

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 informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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