Loading ...
Sorry, an error occurred while loading the content.

validating radio button

Expand Messages
  • Sudhakar
    i have a form with 2 radio buttons in the javascript i have
    Message 1 of 4 , Jan 2, 2008
    • 0 Attachment
      i have a form with 2 radio buttons
      <input name="gender" type="radio" value="Female">
      <input name="gender" type="radio" value="Male">

      in the javascript i have used the following code
      -------------------------------------------------
      valid = true;
      if ( ( document.registrationform.gender[0].checked == false )
      && ( document.registrationform.gender[1].checked == false ) )
      {
      alert ( "Please select the Gender" );
      valid = false;
      return valid;
      }
      -------------------------------------------------

      this code does not work please provide the correct code to validate
      the radio button

      thanks
    • shortestpath
      there is nothing wrong with your code; what exactly is not working?
      Message 2 of 4 , Jan 2, 2008
      • 0 Attachment
        there is nothing wrong with your code; what exactly is not working?
      • Tim Sabin
        The statement return valid; should be *outside* of the if statement, not inside. The way the code is written, the function will never return true. --Tim
        Message 3 of 4 , Jan 2, 2008
        • 0 Attachment
          The statement "return valid;" should be *outside* of the if statement,
          not inside. The way the code is written, the function will never return
          true.

          --Tim Sabin


          Sudhakar wrote:
          > i have a form with 2 radio buttons
          > <input name="gender" type="radio" value="Female">
          > <input name="gender" type="radio" value="Male">
          >
          > in the javascript i have used the following code
          > -------------------------------------------------
          > valid = true;
          > if ( ( document.registrationform.gender[0].checked == false )
          > && ( document.registrationform.gender[1].checked == false ) )
          > {
          > alert ( "Please select the Gender" );
          > valid = false;
          > return valid;
          > }
          > -------------------------------------------------
          >
          > this code does not work please provide the correct code to validate
          > the radio button
          >
          > thanks
          >
          >
          >
          > Visit http://aiaiai.com for more groups to join
          > Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
        • abhijit_dutta2003
          There is no problem with the code; what problems are you getting?
          Message 4 of 4 , Jan 2, 2008
          • 0 Attachment
            There is no problem with the code; what problems are you getting?
            --- In JavaScript_Official@yahoogroups.com, "Sudhakar" <finals27@...>
            wrote:
            >
            >
            > i have a form with 2 radio buttons
            > <input name="gender" type="radio" value="Female">
            > <input name="gender" type="radio" value="Male">
            >
            > in the javascript i have used the following code
            > -------------------------------------------------
            > valid = true;
            > if ( ( document.registrationform.gender[0].checked == false )
            > && ( document.registrationform.gender[1].checked == false ) )
            > {
            > alert ( "Please select the Gender" );
            > valid = false;
            > return valid;
            > }
            > -------------------------------------------------
            >
            > this code does not work please provide the correct code to validate
            > the radio button
            >
            > thanks
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.