View Full Version : Javascript validation in Forms??

09-06-2006, 01:01 PM

I've desgined the form that I wish to use on my website but am having problems with the validation. I can get one or the other of the two functions working just not both. I want an error message when the user does'nt fill in the fields correctly and a 'thank you for summiting' pop up if the form is filled out correctly.

How can I get both of them to work at wonce?:confused:


Check required form elements script-
By JavaScript Kit (http://javascriptkit.com)
Over 200+ free scripts here!

function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
if (!pass){
alert("Error Message here")
return false
return true

Script for error message

<script type="text/javascript">
function createTarget(t){
window.open("comfirm", t, "width=300,height=200");
return true;
Script for pop-up.

Thanks in advance

09-06-2006, 07:06 PM
JavaScript is a bad way to do this, your users just have to disable JavaScript, and then the validation is completely gone.

09-07-2006, 07:41 AM
Thanks for the help. Would it then be best to code all or some of it in php. Could I create the validation in Javascript and the popup in php? This however would not stop the user disabling the javacript?

What would you recommend to be the best wy to do this?

Thanks again

09-07-2006, 10:29 AM
Still can't get it to work!! Does anybody know of or have script that they could direct me to that would allow me to validate the fields and display a conformation?

Also which lanuage is best to code this in? i have no itea where to start with php so at the moment Javascript is the only option that I have I think?

09-07-2006, 01:57 PM
:) Problem solved!! I'd forgotten the && between events!!

09-08-2006, 09:14 PM
You should still do this pretty much entirely server-side. Javascript is useful here only to prevent the user having to wait to submit the form and get a response before realising that s/he has done something wrong; it shouldn't be relied upon.