mwl707 Posted October 5, 2009 Share Posted October 5, 2009 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 Quote Link to comment Share on other sites More sharing options...
jve2211 Posted October 6, 2009 Share Posted October 6, 2009 try ending the lines with ; if (!msg) { // THIS DOES NOT WORK alert ("returning true"); return true; } like that. dont know if it works tho Quote Link to comment Share on other sites More sharing options...
mwl707 Posted October 6, 2009 Author Share Posted October 6, 2009 Thanks but thats not the problem Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.