Solved

Populating a checkbox with info from a database - asp classic

Posted on 2015-01-21
13
113 Views
Last Modified: 2015-01-21
Below is a single line of code that I am trying to work. I want it to pull the information from the database and show the checkbox as checked.

<tr><td><b>Ninite:</b></td><td><input type="checkbox" name="cbxNinite" id="cbxNinite"<%If rs1("ninite") = "on" Then Response.Write "checked"%>><%response.write rs1("ninite")%> </td></tr>
<tr><td><b>Ninite:</b></td><td><input type="checkbox" name="cbxNinite" id="cbxNinite"checked </td></tr>

Open in new window


At the end of the first line of code I tested whether the rs1("ninite") was working. see image below. Doesn't make sense why the checkbox wont check. The second line of code is what it should do.

screenshot
0
Comment
Question by:princeservice
  • 6
  • 6
13 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 350 total points
Comment Utility
your html is invalid, try this:

<tr><td><b>Ninite:</b></td><td><input type="checkbox" name="cbxNinite" id="cbxNinite"<%If rs1("ninite") = "on" Then Response.Write "checked"%>><%response.write rs1("ninite")%> </td></tr>
<tr><td><b>Ninite:</b></td><td><input type="checkbox" name="cbxNinite" id="cbxNinite" checked /></td></tr>

Open in new window

0
 

Author Comment

by:princeservice
Comment Utility
You didn't change anything.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
yes, indeed I did...

your html for the second checkbox was

<input type="checkbox" name="cbxNinite" id="cbxNinite"checked

I changed it to

<input type="checkbox" name="cbxNinite" id="cbxNinite" checked />
0
 

Author Comment

by:princeservice
Comment Utility
That's not the problem. The second line of code is just to show what it would look like if the code:

<%If rs1("ninite") = "on" Then Response.Write "checked"%>

Open in new window



from the first line actually worked.

You can also see from the screenshot that the space does not matter.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
i always eliminate obvious html validation errors if I see them before diving deeper into an issue, that's why I pointed it out. once you get that straightened out and have verified that it wasn't an issue, we can move forward...

I should also point out that you cannot have two checkboxes with the same ID, you'll run into issues if you try to perform any javascript on them.

for your first checkbox, try:

<tr><td><b>Ninite:</b></td><td><input type="checkbox" name="cbxNinite" id="cbxNinite" <%If CStr( rs1("ninite") ) = "on" Then Response.Write "checked"%>><%response.write rs1("ninite")%> </td></tr>
0
 

Author Comment

by:princeservice
Comment Utility
Still doesn't work. This is really weird. The code at the end <%response.write rs1("ninite")%> was just used to make sure that something was actually being returned. It returns "On" every time.

As of right now the code is:
<tr><td><b>Ninite:</b></td><td><input type="checkbox" name="cbxNinite" id="cbxNinite" <%If CStr(rs1("ninite")) = "on" Then Response.Write "checked"%>></td></tr>

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 44

Assisted Solution

by:Rainer Jeschor
Rainer Jeschor earned 150 total points
Comment Utility
Hi,
first of all Big Monty is right that the generated HTML has to be valid - otherwise you might have a lot of side effects.
Can you perhaps post the generated HTML code of your ASP page (not the ASP source)? Can you ensure that the value has no leading / ending space or other whitespace character?
My try:
<tr><td><b>Ninite:</b></td><td><input type="checkbox" name="cbxNinite" id="cbxNinite" <%If Trim(rs1("ninite")) = "on" Then Response.Write "checked" %> /><%response.write "-" & rs1("ninite") & "-"%></td></tr>
<tr><td><b>Ninite:</b></td><td><input type="checkbox" name="cbxNinite" id="cbxNinite" checked />Sample</td></tr>

Open in new window

HTH
Rainer
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
what is the data type coming from the database? boolean or string?
0
 

Author Comment

by:princeservice
Comment Utility
Yes is does have trailing spaces. The datatype is nchar(10). I do not see an option for boolean. What should I use as a datatype?
0
 

Author Comment

by:princeservice
Comment Utility
Oh, and the trim did not work.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
nvarchar is fine, if it was boolean or bit or one of those true/false data types, it would be good to know

try changing your checkbox to

<input type="checkbox" name="cbxNinite" id="cbxNinite" <%If Trim(CStr( rs1("ninite") ) ) = "on" Then Response.Write "checked" %> />
0
 

Author Comment

by:princeservice
Comment Utility
That did it. I guess combining trim and cstr did the job. Monty - you never seem to fail me. Rainer - couldn't have done it without you.
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
glad that worked because I was running out of ideas :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

9 Experts available now in Live!

Get 1:1 Help Now