Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Need value for 'unchecked' checkbox

    Hello all. I have the following line of code to update a value in the DB, but when a value of a checkbox is checked and I change it to unchecked, I get the following error becaues there is no value coming from the checkbox.

    Here is the SQL statement:
    Code:
    Active = Request.Form("cbxActive")
    
    UPDATE tblEquipment SET EqNum = '" & EqNum & "', EqDesc = '" & EqDesc & "', Active = '" & Active & "'   WHERE ID = " & ID
    Here is the error I am getting:
    Code:
    Microsoft JET Database Engine error '80040e07' 
    
    Data type mismatch in criteria expression. 
    
    /Equipment/Eq_AddEdit2.asp, line 81
    Here is the SQL statement in action:
    Code:
    UPDATE tblEquipment SET EqNum = 'DZR-0001', EqDesc = 'Dozer', Active = '' WHERE ID = 12
    How can I get a value for the unchecked checkbox?

    Thanks in advance,

    Parallon

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    As far as i know, the unchecked check box is not in the Request.Form collection. When you are accessing this element in the collection, the element is entered into the collection with an empty value. So testing for this empty value should be enough to see if the box is checked or not. If the box is checked, you receive the value which is defined in the html.
    I am the luckiest man in the world

  • #3
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    I think you have to check which value of checkbox is coming by tracking the query...

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thank you both for your input. I know when it is checked, the value = 'True', so I guess that I could just put an:

    Code:
    Active = Request.Form("cbxActive")
    
    If Active = "" Then 
    Active = 0 
    End If
    I will have to check it when I get back into town.

    Thanks again,

    Parallon
    Last edited by parallon; 03-23-2007 at 06:38 AM.

  • #5
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There are different ways you can check this. It depends on how your database is setup.

    e.g.
    If you have a table that sets checked boxes to active then what you can do is set all the fields to false, then update the fields to true that were checked.

    http://computer-helpforum.com/asp/AD...xes_update.asp

    Code:
    <%
    If Len(Request.Form)>0 Then
    id = Request.Form("id")
    
    		sql =  "UPDATE checkboxes SET active = False"
    		
    		Set updateAll = Server.CreateObject("ADODB.Command")
    		updateAll.ActiveConnection = MM_TEST_STRING
    		updateAll.CommandText = sql
    		updateAll.Execute
    		updateAll.ActiveConnection.Close
    		
    	If Len(id) > 0 Then		
    		sql =  "UPDATE checkboxes SET active = True WHERE id IN (" & id & ")"
    		
    		Set updateChecked = Server.CreateObject("ADODB.Command")
    		updateChecked.ActiveConnection = MM_TEST_STRING
    		updateChecked.CommandText = sql
    		updateChecked.Execute
    		updateChecked.ActiveConnection.Close
    		
    	End If
    	msg = "Records Updated<br>" & sql
    End If
    %>

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thank you for your effort. Actually, the following code worked perfectly. I know it probably isn't the most professional way of doing it, but it is quick and simple.

    Code:
    Active = Request.Form("cbxActive")
    
    If Active = "" Then 
    Active = 0 
    End If
    Thanks again,

    Parallon


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •