Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes 2

Status
Not open for further replies.

nk9100

Technical User
May 13, 2005
67
GB
After reading the FAQs, they specifically relate to a series of checkboxes which have the same group name, I am wonering how I might get the value of the checkbox from the DB, and get the box to be checked.

I tried an If Statement, which didnt work...

Code:
<%
If IsNull(rsCheckUser("educationrecruitmentdifficulties")) Then
%>
<td width="9%">
<input type="checkbox" name="educationrecruitmentdifficulties" value="Yes">
</td>
<%
Else
%>
<%
If rsCheckUser("educationrecruitmentdifficulties") = "Yes" Then
%>
<td width="9%">
<input type="checkbox" name="educationrecruitmentdifficulties" value="Yes" checked>
</td>
<%
End If
%>

Any Ideas?

Life is a journey that always ends up in the same place
 
may not be once it hits some particular record which needs ISNULL condition...so i would suggest you to use...

<input type="checkbox" name="educationrecruitmentdifficulties" <%If IsNull(rsCheckUser("educationrecruitmentdifficulties") OR (rsCheckUser("educationrecruitmentdifficulties")="") THEN response.write "CHECKED"%> value="Yes">

-DNG
 
Thanks to you both

Tek-tips shines through again.

DotNetGnat - would this be worth making an FAQ for?

Life is a journey that always ends up in the same place
 
Why not? i see many people asking this type of question...go ahead and make it a FAQ..i will review it if you want to...

also do you know why we need to check ISNULL() and "" conditions...if not let me know...

-DNG
 
BTW let me remind you...i also suggested something in the past for your thread...but you never replied...let me pull that thread for you...

-DNG
 
Well, isNull and "" are recognised differently by Access, (I dont know if same applies to MySQL/ Oracle etc), I will look into it though, i think when the table is just blank, and never been updated, it is fine, however, after the update, the update inserts a blank field as "", which then when it checks for it after the first update, looks for "" rather than isNull.

I will do an FAQ, and get back to you after I have done my site, (by end of today hopefully!!!!!)

Life is a journey that always ends up in the same place
 
yes you got that straight and it the same case with SQl Server, MYSQL & oracle...

-DNG
 
Hi, back again...slight issue, the orignal code, as posted above, was missing a couple of )'s, at the end of the first 'educationrecruitmentdifficulties', this has now caused it not to work, and all the check boxes come checked when the db is cleared. Any ideas?

Code:
<input type="checkbox" name="educationrecruitmentdifficulties" <%If IsNull(rsCheckUser("educationrecruitmentdifficulties")) OR (rsCheckUser("educationrecruitmentdifficulties")="") THEN response.write "CHECKED"%> value="Yes">
[code]

Life is a journey that always ends up in the same place
 
It needs to be selected if there IS data in the db, rather than not selected.

Life is a journey that always ends up in the same place
 
try this:

Code:
<input type="checkbox" name="educationrecruitmentdifficulties" <%If ( IsNull(rsCheckUser("educationrecruitmentdifficulties")) OR rsCheckUser("educationrecruitmentdifficulties")="" ) THEN response.write "CHECKED"%> value="Yes">

-DNG
 
Hi, Would this be the code to 'Check' the box if the value in the DB is Yes, and not check the box if the value is "" or isNull?

Code:
<Input type="checkbox" name="fieldname" <%If (rsCheckUser("fieldname"))="Yes" THEN response.write "Checked"%> value="Yes">

Life is a journey that always ends up in the same place
 
I think it might just be :)

Life is a journey that always ends up in the same place
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top