Click to See Complete Forum and Search --> : Needed form validation help for Radio Buttons


reub77
01-11-2006, 10:45 PM
I usually work in PHP and in the past have never needed to validate radio buttons. Well now I need to do it in ASP. I have found some code for all the other validation. The trick is applying the radio button validation into the code. I'll put up some snippets of the code to give you an idea of what I'm trying to do:


<%
Function ValidateField(sFieldValue, sFieldType)
Dim bFieldIsOkay

' defaut it to true
bFieldIsOkay = True

' go to the field name to validate the entry
Select Case LCase(sFieldType)
Case "name"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "email"
If Len(sFieldValue) < 5 Then
bFieldIsOkay = False
Else
If Instr(1, sFieldValue, " ") <> 0 Then
bFieldIsOkay = False
Else
If InStr(1, sFieldValue, "@") < 2 Then
bFieldIsOkay = False
Else
If InStrRev(sFieldValue, ".") < InStr(1, sFieldValue, "@") + 2 Then
bFieldIsOkay = False
End If
End If
End If
End If
Case "homephone"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "new1"
If Len(sFieldValue) <> "checked" Then bFieldIsOkay = False
End Select

ValidateField = bFieldIsOkay
End Function
%>


And here is my form:


<form method="POST" NAME="TheForm" action="<%= Request.ServerVariables("Script_Name") %>">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bodytext">
<tr>
<td width="45%">*Are you new to the Heartland Veterinary Clinic? </td>
<td width="35%">
<!--new1-->
<input name="new1" type="radio" value="yes" <%= Request.Form("new1") %>>Yes
<input name="new1" type="radio" value="no" <%= Request.Form("new1") %>>No
</form>


This is just a snippet and so there's a lot of stuff missing. I've taken out the submit buttons in case you are wondering (my code has them). Please help me to know how to add validation for the "new1" radio buttons.

Thanks,
Reuben

jvanamali
01-12-2006, 05:55 AM
Case "new1"
If Len(sFieldValue) = "" Then bFieldIsOkay = False

the value will be either yes or no for the radio button because u have given value="yes" and value="no"

it won't be checked at any time

<!--new1-->
<input name="new1" type="radio" value="yes" <%= Request.Form("new1") %>>Yes
<input name="new1" type="radio" value="no" <%= Request.Form("new1") %>>No

what are thinking of doing with the statements in bold as i told before the value of <%= Request.Form("new1") %> won't be checked

for client side validations better use javascript