View Full Version : XML error messages in Javascript

05-29-2012, 04:03 PM
Hi everyone.

I'm a little bit of a newbie here, so if you could please either help me answer this problem or point me somehwere where I might find the answer it would be greatly appreciated.

I have an online form that has some (external) Javascript validation attached to it. I want to store the error messages in an external xml file and call them during the validation.

Here is a sample of my xml file structure:


<blank_first_name>You must enter your first name.</blank_first_name>


Now, the reason I'm posting this here is that I believe my issue is in the Javascript integration. On form submit, the validate_webform function gets executed.

function loadXMLDoc(dname)
if (window.XMLHttpRequest)
xhttp=new XMLHttpRequest();
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
return xhttp.responseXML;

function validate_webform(thisform)
with (thisform)

if (validate_required(first_name)==false)
first_name_error.innerHTML = xmlDoc.getElementsByTagName("blank_first_name")[0].childNodes[0].nodeValue;
return false;

What happens when I click submit is that the form goes ahead and submits, foregoing all validation. When I replace my xml error messages with a regular text string (i.e. first_name_error.innerHTML = "this is an error"), everything works great.

I have also validated my xml document to ensure there are no errors in it.

I realize that it may be a seemingly easy answer or a very obvious solution to some, but I've been searching for a solution going on 3 days now to no avail, so any help as to why this is not working would be greatly appreciated.

Thank you for your time.

05-30-2012, 10:26 AM
if it works with a plain string, I’d suspect a runtime error (e.g. some required object does not exist) which should be listed in the JS Error Console.

besides that, I’d use JSON instead of XML (esp. since JSON is now built-in into most browsers) so your call would simplify to something like first_name_error.innerHTML = Error_Messages.blank_first_name;