Page 1 of 1

Form Validation Not Working

Posted: Mon Jun 21, 2010 4:08 pm
by devarishi
It is strange that this form validation function is not working as expected:

Code: Select all

function Validate() {

		var tbl 	= document.getElementById("tblCalls");
		var noRows 	= tbl.tBodies[0].rows.length;
		var NotC2Tckt 	= eval(document.VCT.NotC2Tckt.value);

		if (NotC2Tckt > 0 && noRows < 1) {

			alert("Add Rows and Provide Information as the value of 'Not Converted to HD Tickets' is greater than 0.");

			return false;
		}

		else {

			alert("All is fine! Submitting");

			return true;
		}
	}


This is how I am using it in the Form Tag:

Code: Select all

<form name="VCT" action="savevoiceCT.php" method="post" onsubmit="Validate(); return false;" language="jscript">
When the form is valid then the function does display the message:

Code: Select all

alert("All is fine! Submitting");


but then nothing happens. The application as specified in:

Code: Select all

action="savevoiceCT.php" 
is not called at all. The form remains there as it is.

If I remove "return false" from:

Code: Select all

onsubmit="Validate(); return false;" 
then the form is submitted whether it is valid or not. :banghead:

I have used the same method before and it is working fine. Where is the mistake? Any help? :crazy:

Re: Form Validation Not Working

Posted: Mon Jun 21, 2010 4:23 pm
by devarishi
Okay, I have got the solution here: http://www.webreference.com/programming ... t/confirm/


The code snippet:

Code: Select all

onSubmit="return Validate()"
is the one I have used now. The shift of "return" keyword has done the work! :drunk: