View Full Version : Form Error

10-06-2003, 10:30 PM

This section is located on a form. If my users click the radio button, I want them to select option from the drop down menu.
I need a javascript code that will generate an error message if the user only select one of the radio button and not the drop down menu option.

Here's an example

radio button Please add access to my account :
radio button Please remove access to my account :

drop down menu

Here's my function

Function addError(field, errDescription)
If NOT BadFields.Exists(field) Then BadFields.Add field, errorclass
If NOT BadText.Exists(field) Then BadText.Add field, "<br><span style=""color:#FF0000; font-size:11.5px; font-weight:bold;"">" & errDescription & "</span>"
errs = true
addError = errs
End Function

Here's the coding that I am using

If Trim(Request.Form("fm_software")) <> "" AND Trim(Request.Form("fms")) = "" Then errs = addError("fms", "(Please choose whether to add or remove Financial Mangement Software)")
End If

Any suggestions of what I may need to use? Thanks!

10-06-2003, 10:59 PM
That looks like server-side VBScript...

With client-side javascript (which should be used in addition to, but not in place of server-side validation), some validation along these lines is pretty easy. Basically you have to loop through radio button elements, and check the selectedIndex of the dropdown list if one of the radio buttons is checked. Something like:

var checkedflag = false
for (i = 0; i < f.radioname.length; i ++)
if (f.radioname[i].checked) checkedflag = true;

if (checkedflag && f.dropdown.selectedIndex == 0)
return false;

I usually pass the form object to my validation function as the arg "f".

If you need more help, can you provide the relevant portion(s) of the generated HTML? Easier to write the code that way. Or a link would be cool too.