469,357 Members | 1,593 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

form validation

anfetienne
424 256MB
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
Apr 29 '09 #1
8 1053
pronerd
392 Expert 256MB
@anfetienne
Yes. There are thousands of examples of JavaScript form validation available. Just Google for "JavaScript +form +validation".
Apr 29 '09 #2
anfetienne
424 256MB
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?
Apr 29 '09 #3
acoder
16,027 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. <form ... onsubmit="return validate()">
Apr 29 '09 #4
anfetienne
424 256MB
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?
Apr 29 '09 #5
anfetienne
424 256MB
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?

Expand|Select|Wrap|Line Numbers
  1. <script>
  2.   function CopyValue(obj1, obj2)
  3.   {
  4.      var visibleField = obj1;
  5.      obj2.value = visibleField.value;
  6.   }
  7. </script>
  8.  
Apr 29 '09 #6
acoder
16,027 Expert Mod 8TB
Yes, either pass it through the URL:
Expand|Select|Wrap|Line Numbers
  1. location.href="file.php?var="+encodeURIComponent(jsvar);
or set a hidden field value in the form to the variable value:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("hidden").value = jsvar;
Note:encodeURIComponent() encodes the value in case there are any special characters.
Apr 30 '09 #7
anfetienne
424 256MB
does this do so without having to go to another page or refresh?
Apr 30 '09 #8
acoder
16,027 Expert Mod 8TB
Yes, but if you want to avoid that, use Ajax.
Apr 30 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by Phil Powell | last post: by
4 posts views Thread by TG | last post: by
16 posts views Thread by Hosh | last post: by
9 posts views Thread by julie.siebel | last post: by
27 posts views Thread by Chris | last post: by
11 posts views Thread by Rik | last post: by
5 posts views Thread by lucyh3h | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.