Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple checkbox select

Posted on 2006-11-07
8
Medium Priority
?
223 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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…
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/…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

876 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