CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Location
    Malta
    Posts
    13

    validating checkboxes

    Dear All,

    I have an input form where the user must enter his name, surname, e-mail address and choose from three topics, namely Conference, Leisure or Corporate. He can choose as many as he like, however, he has to choose one before submitting the form.

    How can I do the validation on these checkboxes?

    I came up with this code:-

    If request.form("Conference") = "" then
    er = 1
    End IF

    if er <> 1 then
    If request.form("Leisure") = "" then
    er = 1
    End IF
    end if

    if er <> 1 then
    If request.form("Corporate") = "" then
    er = 1
    End IF
    end if

    If er = 1 then
    message = "You have to choose at least one check box"
    end if

    However, how can I stop the form from being submitted?

    Thanks for your help and time
    www.johannmontfort.com

  2. #2
    Join Date
    Jul 2002
    Location
    India
    Posts
    505
    If request.form("Conference") = "" then
    er = 1
    End IF

    if er <> 1 then
    If request.form("Leisure") = "" then
    er = 1
    End IF
    end if

    if er <> 1 then
    If request.form("Corporate") = "" then
    er = 1
    End IF
    end if

    If er = 1 then
    message = "You have to choose at least one check box"
    end if

    What code is that? Clientside or server side? You seem to be confused between client side and server side scripting.

    Before submitting the form, i.e. in the client side you dont have access to the request object. It is a server side object.

    You should be able to access form controls as
    document.<formname>.<controlname>.value

    where <formname> and <controlname> have to be replaced with the name of the form and the control respectively.

    For a javascript example of what you are trying go to

    http://www.w3schools.com/js/tryit.as...s_formvalidate

    Satish

  3. #3
    Join Date
    Apr 2003
    Location
    Malta
    Posts
    13
    Ok thanks mate, I will search for that.
    www.johannmontfort.com

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured