Print Page | Close Window

Checkbox value to DB???

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5027
Printed Date: 30 March 2026 at 6:49pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Checkbox value to DB???
Posted By: Chris
Subject: Checkbox value to DB???
Date Posted: 14 August 2003 at 1:35pm
I'm trying to learn ASP and have a simple problem in regard to some code I'm doing for an update-page:

In one file I feed a recordset with the boolean values from db-field Any_answer (true/false). The variable check_var is set to this value:

<%      
     check_var = CBool(rsEdit("Any_answer"))
     If check_var = TRUE then %>
     <input type="checkbox" name="reply" value="true" checked>
<% Else %>
     <input type="checkbox" name="reply" value="false">
<% End If %>


This works fine. But then, in the other file (the form is calling), I want to update the checked/unchecked value to the db:


rsUpdateEntry.Fields("Any_answer") = CBool(Request.Form("reply"))


Every other field I update works perfectly - they are all strings. But the true/false values seem to disappear when I try to update the field again. Does anyone know what to do?

Chris



Replies:
Posted By: pmormr
Date Posted: 14 August 2003 at 4:01pm
can you give me the full code?

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: 3BEPb
Date Posted: 16 August 2003 at 10:34pm

Chris, here is the first part of your code:

<%check_var = CBool(rsEdit("Any_answer")) %>
     <input type="checkbox" name="reply" value="true"<%If check_var = TRUE then response.write " checked"%>>

I.e. value of checkbox works if checkbox was checked. Then, insert below following code in second file (the form is calling) before SQL update statement:

<%

Dim sReply
If Request("reply")="true" Then
   sReply=1
Else
    sReply=0

End If

%>

And insert this "sReply" as value for Any_answer field, so in case checkbox is checked and it's value = "true", then sReply=1. Else, sReply will be eq. to 0.

Good luck!



Posted By: Chris
Date Posted: 17 August 2003 at 5:33am

Thank you very much. Now it works! Smile

From this I've learned that the Access db wants the numbers (1 for true and 0 for false). My hat off for you.

Chris



Posted By: 3BEPb
Date Posted: 17 August 2003 at 8:54am

Dude, there's nothing to do with database, I didn't even asked you the type of DB :)

I'm not really sure, but Yes/No might also work for Access.



Posted By: b_bonnett
Date Posted: 17 August 2003 at 5:30pm

'Yes/No' is the name of the boolean field type for Access, I'm not sure if you can use them for values (I haven't tried). 'True' and 'False' do work in an Access database, thats what I use, so I'm not sure what was wrong in the original code.

Blair



-------------
Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch


Posted By: 3BEPb
Date Posted: 17 August 2003 at 9:54pm
b_bonnett, I used MS Access extensivly, before I switched to SQL server, so I can assure you, Yes/No works in Access just fine. But anyway, question was about vbscript, not DB :)



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net