form validation trouble

Discussion in 'JavaScript' started by derek34, Dec 1, 2007.

  1. #1
    Hi I'm trying to validate a form but I'm having problems validating the radio buttons and the select menu (or options menu).
    Here's the code I tried:
    <script language="javascript" type="text/javascript">
    function validate_required(field,alerttxt)
    {
    with (field)
    {
    if (value==null||value=="")
      {alert(alerttxt);return false;}
    else {return true}
    }
    }
    function validate_radio(radio,alerttext){
    with (radio)
    {
    if (!radio.checked){
       alert(alerttext);return false;}
       
       else {return true;}
       }
    }
    
       
    function validate_dropdown(drop,alerttext){
    with(drop){
    if (value=="Please Choose..."){alert(alerttext);return false;}
    
    else {return true;}
    }
    }
    function validate_form(thisform)
    {
    with (thisform)
    {
      
    if (validate_required(screen,"Screenname must be filled out!")==false)
      {screen.focus();return false;}
      
    if (validate_required(first,"You must have a first name.")==false)
      {first.focus();return false;}
       
    if (validate_required(last,"you must have a last name.")==false)
      {last.focus();return false;}
       
    if (validate_required(age,"How old are you?")==false)
      {age.focus();return false;}
       
    if (validate_required(occupation,"Please provide a school or occupation")==false)
      {occupation.focus();return false;}
    
    if (validate_required(email,"Email must be filled out!")==false)
      {email.focus();return false;}
      
    if (validate_required(phone,"Please Provide a phone number.")==false)
      {phone.focus();return false;}
      
    if (validate_radio(rent,"Are you renting a computer?")==false)
      {rent.focus();return false;}
      
    if (validate_radio(pizza,"Please Choose a type of pizza")==false)
      {pizza.focus();return false;}
    
    if (validate_dropdown(city,"Please choose a city")==false)
      {pizza.focus();return false;}
    }
    }
    </script>
    Code (markup):
    Any idea why the radio buttons and the option menu validation isn't working?
    Much appreciated.
    - Derek
     
    derek34, Dec 1, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    ajsa52, Dec 1, 2007 IP
  3. derek34

    derek34 Guest

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no I didn't notice that reply ajsa, thanks.
     
    derek34, Dec 2, 2007 IP