converting checkbox value?

1. Senior Member
Join Date
Dec 1969
Posts
516

## converting checkbox value?

How do I get my checkboxes in forms to submit a value of 0 or 1 rather than yes or no?

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## By giving them a value

&#060;INPUT Type="Checkbox" Name="whatever" Value="1"&#062;<BR><BR>But remember, an *unchecked* checkbox has *NO VALUE AT ALL* in the next ASP page (or CGI or any other system, for that matter).<BR><BR>So you have to code something like this:<BR><BR>&#060;%<BR>whatever = Request("whatever")<BR>If IsNumeric(whatever) Then whatever = CINT(whatever) Else whatever = 0<BR>%&#062;<BR><BR>But when you get down to it, since you have to supply the zero value via VBS coding, anyway, what does it *matter* what value you put in the the check box? So an easier way is probably this:<BR><BR>&#060;INPUT Type="Checkbox" Name="whatever"&#062;<BR>and then<BR>&#060;%<BR>If Request("whatever") &#060;&#062; "" Then whatever = 1 Else whatever = 0<BR>%&#062;<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
516

## RE: By giving them a value

ok, my registration form has 10 checkboxes, is there a way of converting them all at once?

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## No...but...

You could put them into an array, but that&#039;s probably more confusing than it&#039;s worth.<BR><BR>Maybe best would be to use a function:<BR><BR>&#060;%<BR>Function cbValue(name)<BR> If Request(name) &#060;&#062; "" Then cbValue=1 Else cbValue=0<BR>End Function<BR>%&#062;<BR><BR>And then, instead of coding<BR>&#060;%<BR>whatever = Request("whatever")<BR>%&#062;<BR>You code<BR>&#060;%<BR>whatever = cbValue("whatever")<BR>%&#062;<BR><BR>Okay?<BR><BR >

5. Senior Member
Join Date
Dec 1969
Posts
516

## sounds good...

...thanks Bill.

#### Posting Permissions

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