Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 15th, 2007, 04:53 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checkboxes undefined when not checked MS Access

I have a page that enters the values of multiple fields into an access DB. It all works (even the checkboxes) until I don’t tick a checkbox.

The value undefined get passed to eh DB and I can not find a way around it anywhere.

I am using JavaScript and the code I am using for the boxes and insert statement is below.


Code:
 sql = "INSERT INTO tblHome (memberID, towncity, towndistance, towndirection, propertytype, flatfloor, flatblock, nobedrooms, nobathrooms, maxnoofpeople, carneeded, carexchange, smoking, swimpool, petcare, childrenallowed, plantcare, picture)"
    sql = sql + "values ('" + varuserID + "', '" + vartowncity + "', '" + vartowndistance + "', '" + vartowndirection + "', '" + varhometype + "', '" + varflatfloorno + "', '" + varflatblock + "', '" + varnobed + "', '" + varnobath + "', '" + varmaxpeople + "', " + varcarneeded + ", " + varcarexchange + ", " + varsmoking + ", " + varswim + ", " + varpet + ", " + varchildallow + ", "+ varplantcare + ", '" + varpic + "');";



Code:
<input type ="checkbox" name ="carYESNO" value = "on"/>
  #2 (permalink)  
Old February 15th, 2007, 05:00 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Its been a long while since I have used access but, if memory serves me, checkboxes are just Bit values (Valued as 0 and 1) a check would be 1 anything else would be 0 so if the checkbox is not ticked in your application set your variable to 0 and pass that into your insert and see if you have better luck. hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
  #3 (permalink)  
Old February 15th, 2007, 05:05 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply; logically that’s exactly what I got. However Access seems to have its own ideas and takes the value of a non ticked checkbox and says its undefined.

This is the message I get if I uncheck just one box:


Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

  #4 (permalink)  
Old February 15th, 2007, 05:10 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

try passing in NULL as the parameter then.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
  #5 (permalink)  
Old February 15th, 2007, 05:12 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry to say that this shows my basic level of understanding, how would i do that?

  #6 (permalink)  
Old February 15th, 2007, 05:16 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Something like:

INSERT INTO <table>(column)Values(NULL)

Also, don't enclose NULL with ' ' (which would make it a string literal) just pass it in as NULL but, before you do this, make sure you have allowed NULL to be inserted into that column.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
  #7 (permalink)  
Old February 15th, 2007, 06:01 PM
Friend of Wrox
 
Join Date: May 2005
Location: , , Norway.
Posts: 189
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...I'll just give you these hints;

1. Read the appendix F in the book ASP 3.0

2. If you are prevented from that, it says;

"Independent check boxes:
      Each NAME is different
      Do not use VALUE
      Test for NAME ="on"

Grouped check boxes:
      All NAMES are the same
     Each box gets its own VALUE

Sample 1, single checkbox:
      <form action = "a" method = get>
      <input type = Checkbox name = "Swahili"> Some text
      <input type = submit>
      </form>

      a:
      If request.querystring("Swahili")="on" then
       ....
      end if

Sample 2, multiple independent checkboxes
      <form action = "a" method = get>
      <input type = Checkbox name = "Swahili"> Some text
      <input type = Checkbox name = "Swa" checked> Some text

      <input type = submit>
      </form>

      a:
      If request.querystring("Swahili")="on" then
       ....
      end if

     If request.querystring("Swa")="on" then
       ....
      end if


Sample 3, groups of checkboxes
      <form action = "a" method = get>
      <input type = Checkbox name = "Swahili" value = "Swahili">Some text
      <input type = Checkbox name = "Swa" value = "Swa" checked> Some text
      <input type = Checkbox name = "Swahi" value = "Swahi"> Some text
      <input type = Checkbox name = "Swai" value = "Swai"> Some text


      <input type = submit>
      </form>

      a:
      If request.querystring("Swahili")="on" then
       ....
      end if

     If request.querystring("Swa")="on" then
       ....
      end if

      If request.querystring("Swahi")="on" then
       ....
      end if

     If request.querystring("Swai")="on" then
       ....
      end if"

And if you are still confused, ask again! Do you need to have VALUE = "ON" in your code?

Mvh
grstad
  #8 (permalink)  
Old February 15th, 2007, 06:35 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I think I get where your going with this, to my general (limited) understanding I do not need the value set
as 'on' as this is the default. As you say I need to query the value passed before it is sent to the db, what
I am ashamed to say is that i didn’t get the examples you gave. Sorry any further help?


  #9 (permalink)  
Old February 15th, 2007, 07:01 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use the following bit of code to pass values from a checkbox to a database true/false field. Maybe you can apply the concept to your situation:
Code:
        strSupport = Request.Form("support")

            if strSupport = "checked" then
                strSupport = "-1"
                 end if
              if strSupport = "" then
                  strSupport = "0"
                 end if
  #10 (permalink)  
Old February 15th, 2007, 07:04 PM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

and here is the form code
Code:
cust_support = rs("Cust_Support")
Support = <input type="checkbox" name="support" id="support" value="checked"
<%
if cust_support = "True" then
%>
checked="checked"
<% end if %>
/>




Similar Threads
Thread Thread Starter Forum Replies Last Post
Registering checked checkboxes in a database KeviJay VB Databases Basics 4 May 14th, 2008 04:44 PM
MS ACCESS 2003 FRONTEND AND MS SQL SERVER 2005 DB mohankumar0709 SQL Server 2005 3 March 23rd, 2007 12:48 AM
Checkboxes undefined when not checked MS Access Morn Classic ASP Basics 0 February 15th, 2007 05:07 PM
Keep track of checkboxes checked in one CASE stmt markw707 Javascript How-To 0 December 29th, 2006 12:28 PM
how to set checked listbox in access application. Skyblue Access VBA 2 September 5th, 2003 09:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.