Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-29-2012, 03:03 PM   PM User | #1
amatsoukas
New to the CF scene

 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
amatsoukas is an unknown quantity at this point
XML error messages in Javascript

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:

Code:
<Webform_Error_Messages>
	
	<blank_first_name>You must enter your first name.</blank_first_name>
	
</Webform_Error_Messages>
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.

Code:
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET","dname",false);
xhttp.send();
return xhttp.responseXML;
} 

function validate_webform(thisform)
{
	xmlDoc=loadXMLDoc("webform_error_msgs_en.xml");
	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.
amatsoukas is offline   Reply With Quote
Old 05-30-2012, 09:26 AM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,872
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
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;
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:50 PM.


Advertisement
Log in to turn off these ads.