Solved

Multiple checkbox select

Posted on 2006-11-07
8
214 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

12 Experts available now in Live!

Get 1:1 Help Now