Solved

CheckBoxes

Posted on 2001-09-07
38
290 Views
Last Modified: 2011-10-03
lemme set this up:
(4 tables)

<--customer table-->
tblCustomers: custID(PK), custName

<--attributes table-->
tblAttributes: attID(PK), custID(FK)

<--this table exists so customers may have multiple logins with different attributes-->
tblCustomerLogin: custLogID(PK)

<--simply a relationship table with no primary keys, just ties the customer login to its attributes-->
tblCustLoginAtt: custLogID, attID

OK, now all i wanna do is when you are editing a particular customer login, not only show ALL of the attributes that are associated with that customer in the form of checkboxes, but also check the ones that are already associated with the given CUSTOMER LOGIN.

I have done things similar to this in the past, but with radio buttons, where theres only ONE possible match, and i could open 2 recordsets and test to see:

<%
do while not rs.eof

if rs("attID")=rs2("attID") then
%>
<input type=radio name="myAtt" value=<%=rs("attID")%> checked>
<%
else
%>
<input type=radio name="myAtt" value=<%=rs("attID")%>>
<%
end if

rs.movenext
loop
%>

easy enough....loop thru rs and when come to match on rs2 then check the radio button, but now, it seems like i have to have a loop nested inside of another loop....which ive tried many different renditions of to no avail.....

any code examples or even explanations would be VERY MUCH appreciated! thx experts in advance! I would post some code, but im basically startin from scratch here, so pls someone show me the light! :D

giving my max 300pts, cuz id like to get resolved asap!

webdude
0
Comment
Question by:webdude
  • 14
  • 11
  • 7
  • +3
38 Comments
 

Author Comment

by:webdude
ID: 6465024
i forgot to include the custID in the tblCustomerLogin table...sorry

webdude
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6465025
Maybe this will help;

sql = "select * from [information] where ID in (" & build & ")Order by "Lastname" Asc"

<input type="checkbox" name="build" id="build" value="<%=rs("ID")%>">
0
 

Author Comment

by:webdude
ID: 6465051
hrm....i have no clue how that will solve my problem. i dont think its in the query but the logic behind displayin the checked and unchecked boxes...unless im missing something here :)
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6465064
My bad... I think I need to re-read the Q...
0
 

Author Comment

by:webdude
ID: 6465082
hehe...np...u still da man anyway :)
0
 
LVL 7

Expert Comment

by:John844
ID: 6465114
here is some basic logic that you can apply

to check a box, you add the keyword checked like
<input type=checkbox name=myname checked>

In your loop to show checkboxes.  loop through the attributes recordset to find any existing settings.  If you find one, then add checked when you show the checkbox.  drop out of the inner loop at this point, since there is no point in continuing if you found a match already.  If you don't find a match and get to the end of the recordset then just show the checkbox.

here is some sample code to get you started...

dim strChecked
dim blnContinue

while not outter.eof
    inner.movefirst
    strChecked = ""
    blnContinue = True
    while not inner.eof and blnContinue
        'if you find a matching attribute for this checkbox
        if inner("chkid") = outter("checkid") then
            strChecked = " CHECKED "
            blnContinue = False
        end if
        inner.movenext
    loop
    outter.movenext
loop

John
0
 
LVL 7

Expert Comment

by:John844
ID: 6465123
oops, forgot to add the line to show the checkbox...

dim strChecked
dim blnContinue

while not outter.eof
   inner.movefirst
   strChecked = ""
   blnContinue = True
   while not inner.eof and blnContinue
       'if you find a matching attribute for this checkbox
       if inner("chkid") = outter("checkid") then
           strChecked = " CHECKED "
           blnContinue = False
       end if
       inner.movenext
   loop
   'show checkbox with checked
   response.write "<input type=checkbox name=chk" & outter("checkid") & strChecked & ">
   outter.movenext
loop
0
 

Author Comment

by:webdude
ID: 6465153
ya...unfortunately...thats my EXACT logic to a tee, and have it that way, but it will not work, i NEVER get a check box...the only thing i DONT have is exiting out of the inner loop when a match is found....how exactly do i exit from the inner loop? or could that even be my prob?
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465160
Does this help you any idea?

select * from test1
select * from test2

select A.ATID, (select 1 from test2 as B where A.ATID=B.ATID) as HasID from test1 as A Where CustId=1
>>from CustLoginID you can find CustID

CustID      ATID        
----------- -----------
1           1
1           2
1           3
2           4

(4 row(s) affected)

CustLoginID ATID        
----------- -----------
1           1
1           2

(2 row(s) affected)

ATID        HasID      
----------- -----------
1           1
2           1
3           NULL

(3 row(s) affected)

0
 

Author Comment

by:webdude
ID: 6465168
here is my current code segment for your viewing pleasure...


<%
         
          do while not rs.eof
          %>
     <tr>
          <td>&nbsp;</td>
          <%
          do while not rs2.eof
               if rs2("projID")=rs("projID") then
                    doCheck="checked"
               else
                    doCheck="&nbsp;"
               end if
          rs2.movenext
          loop
          %>
          <td><input type=checkbox name="myProj" value=<%=rs("projID")%> <%=doCheck%>><%=rs("projName")%></td>
     </tr>

     <tr>
          <td colspan=5><img src="images/space.gif" width=1 height=3></td>
     </tr>
     <%
          rs.movenext
          loop
     %>
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465187
if you want to exit out of the inner loop, use
EXIT DO
<%
         
         do while not rs.eof
         %>
    <tr>
         <td>&nbsp;</td>
         <%
         do while not rs2.eof
              if rs2("projID")=rs("projID") then
                   doCheck="checked"
                   EXIT DO
              else
                   doCheck="&nbsp;"
              end if
         rs2.movenext
         loop
         %>
         <td><input type=checkbox name="myProj" value=<%=rs("projID")%> <%=doCheck%>><%=rs("projName")%></td>
    </tr>

    <tr>
         <td colspan=5><img src="images/space.gif" width=1 height=3></td>
    </tr>
    <%
         rs.movenext
         loop
    %>
0
 

Author Comment

by:webdude
ID: 6465222
thx for the exit do (duh..) hehe

still same tho....i never get a check box....grrr

dont give up on me yet guys!
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6465226
Ouch... Ummmm opening 2 recordsets?  Can't you just Join statements to accomplish this?  Post your database schema and maybe we can make this more efficient, thus making your code better.
0
 

Author Comment

by:webdude
ID: 6465241
thats what i thought at first too, trying an outer join...but the db schema is in the first post above....here it is again:

<--customer table-->
tblCustomers: custID(PK), custName

<--attributes table-->
tblAttributes: attID(PK), custID(FK)

<--this table exists so customers may have multiple logins with different attributes-->
tblCustomerLogin: custLogID(PK), custID

<--simply a relationship table with no primary keys, just ties the customer login to its attributes-->
tblCustLoginAtt: custLogID, attID
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465245
Webdude,

have you tried my SQL statement above? then you don't have to go through 2 do while loop.
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465249
Webdude,

have you tried my SQL statement above? then you don't have to go through 2 do while loop.
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6465252
Sorry, didn't see them above, what information are you trying to get out of these tables?  (what are your SQL statements)
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465253
Change rs2("projID")=rs("projID") to
Trim(rs2("projID")) = Trim(rs("projID"))
to see if it works.  The = will compare 2 variables case sensitive.  Also, usually, when you get from database you will have trailing spaces.
0
 

Author Comment

by:webdude
ID: 6465256
no i havent tried it yet phunc, cuz its a lil confusing....sorry....i understand your doing like subqueries with aliases but its still cornfusing :)
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 3

Expert Comment

by:phuctran
ID: 6465264
These are SQL statements.
select * from test1
select * from test2
select A.ATID, (select 1 from test2 as B where A.ATID=B.ATID) as HasID from test1 as A Where CustId=1
>>from CustLoginID you can find CustID

These are the results of those statements above
CustID      ATID        
----------- -----------
1           1
1           2
1           3
2           4

(4 row(s) affected)

CustLoginID ATID        
----------- -----------
1           1
1           2

(2 row(s) affected)

The last SQL statement will give you this recordset:
ATID        HasID      
----------- -----------
1           1
2           1
3           NULL

then do loop, if HasID = 1 then "checked".

0
 

Author Comment

by:webdude
ID: 6465277
first off phuc....the trim didnt werk

secondly, i understood all that u re-explained, but still have no clue what you are doing in that subquery sorry
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465289
Webdude,

remember to have "" in you html code :)

 value=<%=rs("projID")%> <%=doCheck%>><%=rs("projName")%

if rs("projID") = "hello"
then you will have
 value=hellochecked> that is why you don't get "checked"

change doCheck="checked"
to doCheck=" checked "

0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6465295
Try this query:

Select custName,tblCustomers.custID,tblCustLoginAtt.attID,tblCustomerLogin.custLogID from tblCustomers Join tblAttributes On tblCustomers.custID = tblAttributes.addID
  Join tblCustLoginAtt on tblCustLoginAtt.attID = tblAttributes.attID
  Join tblCustomerLogin on tblCustLoginAtt.custLogID = tblCustomerLogin.custLogID
Where custName = 'webdude'

this should give you what you need
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465299
Oh, what I meant to have "" in your html code is

 <input type="text" name="txtName" value="txtValue">

so you should have
value="<%=rs("projID")%>" <%=doCheck%>><%=rs("projName")%

one thing might happen is if rs("projID") has two words then you will have trouble later.
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6465316
With my above query, try this

set cn = rs.execute ("Select custName,tblCustomers.custID,tblCustLoginAtt.attID,tblCustomerLogin.custLogID from tblCustomers
Join tblAttributes On tblCustomers.custID = tblAttributes.addID
 Join tblCustLoginAtt on tblCustLoginAtt.attID = tblAttributes.attID
 Join tblCustomerLogin on tblCustLoginAtt.custLogID = tblCustomerLogin.custLogID")

while not rs.EOF
  %>
  <input type=radio name="myAtt" value=<%=rs("attID")
    if rs("CustName") = "webdude" then
      response.write ("  checked  ")
    end if
  %>
  ><%=rs("CustName")%><br>
<%rs.movenext
Wend%>
0
 

Author Comment

by:webdude
ID: 6465331
phuc...that makes no difference.....i tried " checked" same problem....

and also btw....u DONT wanna use "" around numbers, it makes it a string FYI

chicken...im tryin urs now

brb
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6465338
I just don't know if I'm following what you are doing right, but it should be that complicated with the right query (try to always avoid 2 recordsets if you can)
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465360
I agree with thunderchicken.  You should try to rewrite your SQL query to avoid loop into loop.  But because you want to get it works asap, then we will help you with your code.

Let do step by step:
Change

         do while not rs2.eof
              if rs2("projID")=rs("projID") then
                   doCheck=" checked "
              else
                   doCheck=" checked "
              end if
         rs2.movenext
         loop

to see if you actually go into the inner while loop.

Then try to do:
<td><input type=checkbox name="myProj" value=<%=rs("projID")%> <%=doCheck%>><%=rs("projName")%></td>
to
<td><input type=checkbox name="myProj" value=<%=rs("projID")%> <%=doCheck%>><%=rs("projID")%> and <%=rs2("projID")%></td>
to see their values.

0
 
LVL 3

Expert Comment

by:phuctran
ID: 6465372
Sorry, it should be read:

Then try to do:
        do while not rs2.eof
             if rs2("projID")=rs("projID") then
                  doCheck=" checked "
                  strTemp = rs("projID")
                  exit do
             else
                  doCheck=" checked "
                  strTemp = rs("projID")
             end if
        rs2.movenext
        loop

<td><input type=checkbox name="myProj" value=<%=rs("projID")%> <%=doCheck%>><%=rs("projName")%></td>
to
<td><input type=checkbox name="myProj" value=<%=rs("projID")%> <%=doCheck%>><%=rs("projID")%> and <%=strTemp%></td>
to see their values.

One more thing is that rs2 does not get any record at all.  check your sql statement again.

0
 
LVL 3

Accepted Solution

by:
phuctran earned 150 total points
ID: 6465377
oops,
strTemp = rs2("projID")
0
 

Author Comment

by:webdude
ID: 6465379
well guys....i got it...i ended up just putting it all into a function and mysteriously it werked, even tho its my same logic as b4......so i really hate these positions where multiple ppl help with same q, and i find answer somewhere else....

so on that note, instead of deleting question, i would like to give the 300 points to phuc and thunder...so i will accept phucs response, and if u could be so kind, mebbe split the points with thunder for me?

thx again guys and sorry for the point-split
0
 

Author Comment

by:webdude
ID: 6465381
pls split points with thunder...thx guys for all your efforts!
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6465386
Thanks, if you want to split, you will need to post in Community Support.
0
 

Author Comment

by:webdude
ID: 6465403
me or phuc?

i was thinkin phuc could just ask a question for 150 pts, and accept your comment as answer....if that wont werk lemme know

0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6465439
they will use that for their own questioning, but don't worry about it, phuctran posted a 0 point question in CS and they will take care of it

glad we could help
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6468578
I can fix this for you be reducing this question to 150 and then post another question for 150 for the other expert here, or you can do this directly, including the link to this question.

Is that what you want, 150 to each (just want to confirm)?

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6468587
Checked the CS Question which confirms a 150/150 point split.  Reduced this to 150 points, and created another for thunderchicken at the following link:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=asp&qid=20180575

All now completed.

Moondancer
Community Support Moderator @ Experts Exchange
0
 

Author Comment

by:webdude
ID: 6470469
thanks again!
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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

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