Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Form Error

  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Thanked 0 Times in 0 Posts

    Form Error


    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!
    Last edited by briggsc; 10-06-2003 at 10:37 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    41° 8' 52" N -95° 53' 31" W
    Thanked 0 Times in 0 Posts
    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.
    Last edited by whammy; 10-06-2003 at 11:03 PM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


    Posting Permissions

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