Jump to content

[SOLVED] return true ??


mwl707

Recommended Posts

Hi I have a script that validates the entries on a form. If there are errors then it alerts the user and return false. This works fine. But if there are no errors and i return TRUE nothing happens the form is not sent . the line in my PHP is this

<form id='form1' name='form1' style='background-color:ccc' method='post' onsubmit='return form_val($importedjobnumber) ' action='processform.php?job=new'

 

and this is my AJAX , Can anyone help me please its driving me mad !!

 

// JavaScript validate form                                                                                               
function  form_val() {

if(XMLHttpRequestObject) {

XMLHttpRequestObject.open("GET", "form_validate.php", true);    // This php script gets error messages to be displayed 

XMLHttpRequestObject.onreadystatechange = function() { 
if (XMLHttpRequestObject.readyState == 4 &&  XMLHttpRequestObject.status == 200) { 
var xmlDocument = XMLHttpRequestObject.responseXML;
msg = ""

elem = document.getElementById('form1').elements;
leg = elem.length

for (i=1; i<leg; i++) {
Vname = ""
Vname = elem[i].name

if (Vname) {

	try {
	error_entry = xmlDocument.getElementsByTagName( Vname );	
	validator = xmlDocument.getElementsByTagName( "V" +  Vname );

	vv = validator[0].firstChild.data  // <Vevent> text </Vevent> 
	ee  = error_entry[0].firstChild.data 	 // <event> must enter a place </event> 
	eeform = ""
	eeform = document.getElementById(Vname).value

	if (ee && eeform )  {document.getElementById(Vname).style.backgroundColor='#E1E1E1' }	// return red box to grey  
	if (ee && !eeform ) {
	document.getElementById(Vname).style.backgroundColor='red'	
	msg += ee ;
	msg += " Validator " + vv 
	msg += "\n\n" 
	} //if
	} 
	catch(err) { } 
} // if 

} //for

if (!msg) {  // THIS DOES NOT WORK 
alert ("returning true")
return true
} 

alert ("Please correct the following \n\n" + msg ) 

} 
} 
XMLHttpRequestObject.send(null); 
}
return false ; 

} // end of function  

Link to comment
https://forums.phpfreaks.com/topic/176601-solved-return-true/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.