View Full Version : Make a checkbox required field in a form
Jimbosar
10-15-2002, 10:37 PM
Hi,
It is a simple question so there must be a simple answer.....first time I am doing such a thing so I have to ask...
I created a field with acheckbox in my form (like the ones: I agree with the TERMS & CONDITIONS) so you have to check the box in order to move on with the registration. With other words I want to make the field compulsory.
I would appreciate any thoughts on this...
Thanks
Roy Sinclair
10-15-2002, 11:24 PM
If Peter Bailey posted this it'd be a troll :D but look here (http://www.peterbailey.net/fValidate/site.php).
Jimbosar
10-16-2002, 12:01 AM
Thanks Roy Sinclair,
but.....unfortunately the checkbox validation is not there....not yet
...:mad: :mad: :mad: .....
if you know any other site would be much appreciated
whammy
10-16-2002, 12:53 AM
You simply request the variable of the checkbox on the form you post to (even if you post it to itself), i.e.:
Dim mycheckbox
mycheckbox = Request.Form("mycheckbox")
If mycheckbox = "" Then
' Either redirect to the form that posted
' it with a querystring like ?E=1
' so you know there's an error, or
' display the subroutine that presents
' your form again (if you posted it to itself).
Else
' Do whatever you want to do if the var has a value
End If
That's very basic validation, in any language... if I were you I'd look at some tutorials like the ones on:
http://www.webmonkey.com/authoring <!-- especially these!!
http://www.liquidrage.com
http://www.haneng.com
And you may want to check out my example email form, as it has good basic validation that you can learn from (as well as being a good example of posting a form to itself, which is useful to get a handle on since that's how ASP.NET works!):
http://www.solidscripts.com/email.txt
P.S. make sure your checkbox has a value, like:
<input type="checkbox" name="mycheckbox" value="Y" />
:)
Jimbosar
10-16-2002, 01:26 AM
Thanks a lot :)
whammy
10-16-2002, 01:31 AM
No problem... I have no beef with Roy Sinclair's post - but it looks to me like that API he referenced is total javascript, whereas if you're using ASP (or any other server-side language), you don't want to rely on javascript as the user MAY have it disabled (or have a browser that isn't standards compliant or perhaps a PDA, etc.).
Since you're using ASP, it will return pure HTML to the client, so there should be no problems with compatibility assuming you are coding correct (X?)HTML.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.