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

Thread: Validate Date

  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Validate Date

    I want to validate 5 dates in a form using javascript. How can I do that ? Also I want to validate the Gender. Means the person has to select either male or female.

    Below is the link of the form.

    http://www.mastek.com/icm2006/profile_form.htm

    Regards,

    Hiren.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Not sure what you mean by "validate" as you are using select boxes. (By the way, 2005 is the last year available). Are you wishing to check that "departure date" is after "arrival date" or something?

    Validate gender (one or other radio button must be selected):-

    if (!document.business_form.sex[0].checked && !document.business_form.sex[1].checked)
    {
    alert ( "Please Select Gender Male or Female" );
    return false;
    }
    Last edited by Philip M; 07-29-2006 at 11:16 AM.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    The generic way to validate a group of any number of radio buttons:
    Code:
    function hasRadioChecked(radGroup){
      var len = radGroup.length;
      for (var i=0; i<len; i++){
        if (radGroup[i].checked){
          return true;
        }
      }
      return false;
    }
    
    //to use
    function validate(frm){
      if (!hasRadioChecked(frm.gender)){
          alert("You must select one.");
          frm.gender[0].focus();
          return false;
      }
      ...
      return true;
    }
    Last edited by glenngv; 07-30-2006 at 07:51 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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