Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Checkbox value to DB???
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Checkbox value to DB???

 Post Reply Post Reply
Author
Chris View Drop Down
Newbie
Newbie
Avatar

Joined: 01 March 2003
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chris Quote  Post ReplyReply Direct Link To This Post Topic: Checkbox value to DB???
    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
Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 14 August 2003 at 4:01pm
can you give me the full code?
Back to Top
3BEPb View Drop Down
Groupie
Groupie


Joined: 07 August 2003
Location: United States
Status: Offline
Points: 81
Post Options Post Options   Thanks (0) Thanks(0)   Quote 3BEPb Quote  Post ReplyReply Direct Link To This Post 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!

Back to Top
Chris View Drop Down
Newbie
Newbie
Avatar

Joined: 01 March 2003
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chris Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
3BEPb View Drop Down
Groupie
Groupie


Joined: 07 August 2003
Location: United States
Status: Offline
Points: 81
Post Options Post Options   Thanks (0) Thanks(0)   Quote 3BEPb Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post 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, The Plane Gallery
Greetings From Christchurch
Back to Top
3BEPb View Drop Down
Groupie
Groupie


Joined: 07 August 2003
Location: United States
Status: Offline
Points: 81
Post Options Post Options   Thanks (0) Thanks(0)   Quote 3BEPb Quote  Post ReplyReply Direct Link To This Post 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 :)
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.