form validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    form validation

    is there a way to check if all form fields are filled in? i can do it singular but just need to know if it can be done
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    Originally posted by anfetienne
    is there a way to check if all form fields are filled in? i can do it singular but just need to know if it can be done
    Yes. There are thousands of examples of JavaScript form validation available. Just Google for "JavaScript +form +validation".

    Comment

    • anfetienne
      Contributor
      • Feb 2009
      • 424

      #3
      i have a form validation method that i learned already....i cant find if its possible to validate a form as a whole rather than checking if a field is filled out?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Yes, you can. Check the links in the Offsite Links sticky. The basic idea is to validate all the elements of the form one by one onsubmit:
        Code:
        <form ... onsubmit="return validate()">

        Comment

        • anfetienne
          Contributor
          • Feb 2009
          • 424

          #5
          i think im going about this the wrong way.....is it possible for javascript to do this i.e. say if the form returns no errors then do something else?

          Comment

          • anfetienne
            Contributor
            • Feb 2009
            • 424

            #6
            ok ive done the validation..... is there a way i can get a value thats in javascript into a php.....i want to get the value that goes into obj2 into a php var......is it possible?

            Code:
            <script>
              function CopyValue(obj1, obj2)
              {
                 var visibleField = obj1;
                 obj2.value = visibleField.value;
              }
            </script>

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Yes, either pass it through the URL:
              Code:
              location.href="file.php?var="+encodeURIComponent(jsvar);
              or set a hidden field value in the form to the variable value:
              Code:
              document.getElementById("hidden").value = jsvar;
              Note:encodeURIC omponent() encodes the value in case there are any special characters.

              Comment

              • anfetienne
                Contributor
                • Feb 2009
                • 424

                #8
                does this do so without having to go to another page or refresh?

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Yes, but if you want to avoid that, use Ajax.

                  Comment

                  Working...