two forms in 1 validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • firdzz
    New Member
    • Mar 2008
    • 3

    two forms in 1 validation

    Hi!

    I'm quite new with this web development. I have a problem to validate a form that if the user selected 'other' in the dropdown list, they need to key in something in another text field form. Here's my javascript:

    if (theForm.Univer sity1a.value == "Other" *can we put something here?* theForm.Univers ity1.value == "")
    {
    alert("You have selected Other. Please enter a value for the \"University \" field.");
    theForm.Univers ity1.focus();
    return (false);
    }

    Thanks in advance!
  • aswath
    New Member
    • Mar 2008
    • 18

    #2
    Originally posted by firdzz
    Hi!

    I'm quite new with this web development. I have a problem to validate a form that if the user selected 'other' in the dropdown list, they need to key in something in another text field form. Here's my javascript:

    if (theForm.Univer sity1a.value == "Other" *can we put something here?* theForm.Univers ity1.value == "")
    {
    alert("You have selected Other. Please enter a value for the \"University \" field.");
    theForm.Univers ity1.focus();
    return (false);
    }

    Thanks in advance!
    if the user choose others, he must be shown a textbox where he can enter his choice.. is that what u r asking dude.....
    regards

    Comment

    • firdzz
      New Member
      • Mar 2008
      • 3

      #3
      Originally posted by aswath
      if the user choose others, he must be shown a textbox where he can enter his choice.. is that what u r asking dude.....
      regards
      nope. what i mean is when the user submit the form, the javascript will check if the user have selected other, they must key in something in the textbox and cannot be blank. I'm not sure what to put to replace the comma (,) since it is not checking the blank textbox.


      if (theForm.Univer sity1a.value == "Other" , theForm.Univers ity1.value == "")
      {
      alert("You have selected Other. Please enter a value for the \"University \" field.");
      theForm.Univers ity1.focus();
      return (false);
      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by firdzz
        nope. what i mean is when the user submit the form, the javascript will check if the user have selected other, they must key in something in the textbox and cannot be blank. I'm not sure what to put to replace the comma (,) since it is not checking the blank textbox.


        if (theForm.Univer sity1a.value == "Other" , theForm.Univers ity1.value == "")
        {
        alert("You have selected Other. Please enter a value for the \"University \" field.");
        theForm.Univers ity1.focus();
        return (false);
        }
        Perhaps you are looking for && (and)?

        [CODE=javascript]if (theForm.Univer sity1a.value == "Other" && theForm.Univers ity1.value == "")[/CODE]

        Comment

        • vee10
          New Member
          • Oct 2006
          • 141

          #5
          Hi,
          if (theForm.Univer sity1a.value == "Other" , theForm.Univers ity1.value == "") ',' should be replaced with or condition || since u want the value should not be null or selected other

          Originally posted by firdzz
          nope. what i mean is when the user submit the form, the javascript will check if the user have selected other, they must key in something in the textbox and cannot be blank. I'm not sure what to put to replace the comma (,) since it is not checking the blank textbox.


          if (theForm.Univer sity1a.value == "Other" , theForm.Univers ity1.value == "")
          {
          alert("You have selected Other. Please enter a value for the \"University \" field.");
          theForm.Univers ity1.focus();
          return (false);
          }

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by vee10
            Hi,
            if (theForm.Univer sity1a.value == "Other" , theForm.Univers ity1.value == "") ',' should be replaced with or condition || since u want the value should not be null or selected other
            If "Other" is selected then there should be a value for University1 as well therefore it's && (see my reply above) that the OP wants.

            Comment

            • firdzz
              New Member
              • Mar 2008
              • 3

              #7
              Originally posted by r035198x
              If "Other" is selected then there should be a value for University1 as well therefore it's && (see my reply above) that the OP wants.
              Thanks it's working =D. Thanks to others also for comments =D

              Comment

              Working...