Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to deal with checkbox data type?

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
0
0
Dear Friends:
I am using a checkbox control in my ASP page, the data need to be stored in an Access database. I know that when checkbox is checked, it has value "on", nothing otherwise. How can I convert it into yes/no format in ASP page in order for my MS ACCESS can accept it. I met mismatch error when I send the data into my database.

Your helps is very important for me.

Thank you

Haijun
 
Hi Longmatch

Hmmm, actually I think its the checked value (True or False) that you want.

<form name=&quot;F1&quot;>
<input type=&quot;checkbox&quot; name=&quot;C1&quot; onClick=&quot;TestMe()&quot;>
</Form>

<script language=&quot;VBScript&quot;>
function TestMe()
if document.F1.C1.checked = true then
Msgbox &quot;I am True&quot;
else
Msgbox &quot;I am False&quot;
end if
end function
</Script>
 
Dear Kevinclark:
Thank you for your help again.
Actually I had this problem when I submitted my form data to the Access database on the back. I can not insert the checkbox variable into database due to the Mismatch error. I am not sure what is the default value for Access when checkbox is checked.
I will work on it, hoping I can fix it by myself. I am very glad to continue to get your help.

Haijun
 
No problem Longmatch

If the Database Field is set for a Boolean Type, maybe it is seeing your variable as a string - Would cause a MisMatch error.


if document.F1.C1.checked = true then
chkVariable = True 'Could see this as a string
else
chkVariable = False 'Could see this as a string
end if

'When writting to database you could cast the variable
rsSample(&quot;chkBoxField&quot;) = CBool(chkVariable)

 
Dear Kevinclark:
I tried your suggestion, it did not work for some reason, not sure why. It still give me the same error &quot;type mismatch&quot;. I alse tried to unchange everything and reset the datatype in my Access database for this item from yes/no to text. It gave me another error
'FORM_ID_198163500.Continuity' cannot be a zero-length string, even though this checkbox was checked.

I do not know why.

Do you think I need to set up the reference in access database.


haijun
 
If you are writing ASP code, you can't access the checkbox with the document object - that is in the browser object model!

You access the Value attribute of the checkbox like this - Request.form(&quot;Checkbox1&quot;) Checkbox1 is the HTML name of the form field!

This will let to get the value of the checkbox on your HTML form. Set the action attribute of the form to the .asp page you want to process the form and the Method to &quot;Post&quot; and the Value of the checkbox to some value you want, ie.

<input type = checkbox name = checkbox1 value = &quot;YES&quot;> then the above code could be used this way:

variable1 = request.form(&quot;checkbox1&quot;)

this will put the value of YES into the variable and then you can use that to update the database field.

let us know how you make out!
 
Dear: Rkfox:
This problem is solved after I changed delected the code &quot;value = <%= session(&quot;Continuity&quot;)%>&quot; from the <Input=&quot;checkbox&quot;, Name=continuity, value =&quot;<%= session(&quot;Continuity&quot;)%>&quot;. Actually I got this code from one book, I dont know what <%=session(&quot;variablename&quot;) for in this code. But I used this format for other types of input, there is no problem at all.
Thank you very much.

Haijun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top