how to validate marital status in java script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • banjuu
    New Member
    • Sep 2007
    • 10

    how to validate marital status in java script

    [HTML]<tr>
    <td class="headingg ry" height="20">Mar tial Status</td>
    <td class="alternat e3"><div align="left"><s pan >

    <select>
    <option value="married" selected="selec ted">Married</option>
    <option value="single"> Single</option>
    <option value="divorced ">Divorced</option>
    </select>
    </span></div></td>
    </tr>[/HTML]
    Last edited by acoder; Sep 12 '07, 11:20 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    Please remember to use code tags when posting code.

    Changed a typo in the title - I think you meant marital rather than martial.

    How do you want to validate it?

    Comment

    • banjuu
      New Member
      • Sep 2007
      • 10

      #3
      Originally posted by acoder
      Welcome to TSDN!

      Please remember to use code tags when posting code.

      Changed a typo in the title - I think you meant marital rather than martial.

      How do you want to validate it?
      [HTML]<tr>
      <td class="headingg ry" height="20">Mar tial Status</td>
      <td class="alternat e3"><div align="left"><s pan >

      <select>
      <option value="blank" selected="selec ted"> </option>
      <option value="single"> Single</option>
      <option value="divorced ">Divorced</option>
      </select>
      </span></div></td>
      </tr>
      [/HTML]
      it shows blank in display form.

      my aim is to validate tht martial status tht should alert saying plz select one of the options in martial status.
      Last edited by acoder; Sep 12 '07, 12:04 PM. Reason: Added code tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You originally had "married" as the first option. Now it makes more sense.

        Do you want this validation to happen when the user submits the form?

        Comment

        • banjuu
          New Member
          • Sep 2007
          • 10

          #5
          yaaaaaaaaa.


          plz help me yaar .how to do tht.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Give the marital select element an id,e.g.
            [HTML]<select id="marital">[/HTML] Add a validation function which returns true or false using onsubmit on the form:
            [HTML]<form ...onsubmit="re turn validate(this); ">[/HTML]
            Your validate function could look something like:
            [CODE=javascript]function validate(form) {
            var marital = document.getEle mentById("marit al");
            if (marital.value == "blank") {
            alert ("whatever message you want to put here.");
            return false;
            }
            return true;
            }[/CODE]

            Comment

            Working...