By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,499 Members | 1,284 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,499 IT Pros & Developers. It's quick & easy.

Form validation with JavaScript

P: n/a
I'm looking for an example of form validation by JavaScript before it's
processed by a PHP script.

Any help will be appreciated.
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Amir wrote:
I'm looking for an example of form validation by JavaScript before it's
processed by a PHP script.


This would be more on-topic in comp.lang.javascript. Anyway...

What are you trying to validate? It's a little difficult to give you
anything useful unless that's known.

The basic format you should be looking at is:

<form ... onsubmit="return validate(this);">
function validate(form) {var elem = form.elements;
/* ... */
}

where the controls within the form can be accessed through the elements
collection (referenced by elem for convenience, above), and the validate
function returns false if validation fails; true otherwise.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 17 '05 #2

P: n/a
Michael Winter wrote: Amir wrote:

I'm looking for an example of form validation by JavaScript before it's processed by a PHP script.

This would be more on-topic in comp.lang.javascript. Anyway...

What are you trying to validate? It's a little difficult to give you anything useful unless that's known.

The basic format you should be looking at is:

&nbsp; &lt;form ... onsubmit="return validate(this);"&gt;


&nbsp; function validate(form) {var elem = form.elements;
&nbsp;&nbsp;&nbsp; /* ... */
&nbsp; }

where the controls within the form can be accessed through the elements collection (referenced by elem for convenience, above), and the validate function returns false if validation fails; true otherwise.

Mike

Thanks! This is exactly what I needed:

&lt;form ... onsubmit="return validate(this);"&gt;

I got the validation function, just couldn't figure out how to activate it before processing the form by a PHP script.

-Amir
Jul 17 '05 #3

P: n/a
HEllo,

on 04/26/2005 03:38 PM Amir said the following:
I'm looking for an example of form validation by JavaScript before it's
processed by a PHP script.


You may want to take a look at this popular class for generating and
validating forms that can generate the necessary Javascript for you to
perform many kinds of common validation types on the client site. It can
also perform the same types of validation on the server side with class
PHP code itself.

http://www.phpclasses.org/formsgeneration
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.