This topic is locked

Checkbox values - 'Yes' or 'On'?

4/3/2005 1:40:04 PM
ASPRunnerPro General questions
A
apaull author

I have a form with a few checkboxes and for some reason the checked value for them when entered into the database is "on", as opposed to "yes". As a result, when the database record is edited, the editing page fails to pick up on the previously checked boxes...
When I first started my project they were being listed as "yes"... have I done something to change them? I can't find any way of of changing them back...
Cheers,
Adam

Sergey Kornilov admin 4/3/2005

When you use checkboxes on Edit/Add pages ASPRunner always puts 0 or 1 into database field. This means you need to use database type that accepts integer values. This would Yes/No field in MS Access or TINYINT field in SQL Server.
Using text fields for this purpose is not good.

A
apaull author 4/4/2005

Thanks for that, works a treat...
Just one final question - is it possible to have a check box as a required field? Something along the lines of "I have read the terms and conditions and wish to proceed", that sort of thing.
I've tried playing around with the code but with no luck.
Cheers,
Adam

Sergey Kornilov admin 4/4/2005

Hi,
you can use this code snippet. Replace fieldname by your check box field name.

<form name=editform onSubmit="if

(!document.forms.editform.fieldname.checked)

{ alert('You have to agree with ...'); return false;  }" >

jmisson 9/25/2005

Hi,
This is building on from the previous answer.
I also have a check box I wish to make sure is ticked, the only problem is I also wish to validate the fields, thus I have two actions for the 1 on submit button
"if

(!document.forms.editform.fieldname.checked)

{ alert('You have to agree with ...'); return false; }" >
and
" return validate();">
How do I include both of these in the one action (if this is at all possible)
Many thanks
Julie

Sergey Kornilov admin 9/25/2005

Julie,
you need to put this Javascript code into the very beginning of validate() function that can be found in include/validate.htm file. Make sure you return false if validation not passed.