Go Back   CodingForums.com > :: Client side development > JavaScript programming

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 10-17-2006, 05:49 PM   PM User | #1
mynameisdave145
New Coder

 
Join Date: Oct 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
mynameisdave145 is an unknown quantity at this point
Having some Trouble...

ok, so here is the code im using:
Code:
function getmessage()
{
//Get list of definition tags
var glossary = xmlDoc.getElementsByTagName('definition');
//Elements plaecholder
var elements = new Array();
//document.write(glossary.length); //Test length of glossary in words

//Using length of glossary, put information into elements placeholder
	for (i=0;i<glossary.length;i++)
	{
		// Get words and put them into first element of array
		var word_length = xmlDoc.getElementsByTagName("word");
		var word = word_length[i].childNodes[0].nodeValue;
		 	//document.write(word);
		elements[i] = new Array(word);
		//	document.write(elements[i][0]);

		//Get sections and put them into the second element of array
		var section_length = xmlDoc.getElementsByTagName("section");
		var section = section_length[i].childNodes[0].nodeValue;
		elements[i][1] = section;

		//Get definitions and put them into third element of array
		var def_length = xmlDoc.getElementsByTagName("def");
		var def = def_length[i].childNodes[0].nodeValue;
		elements[i][2] = def;

		document.write(elements[i][0]);
		document.write("<br>");
		document.write(elements[i][1]);
		document.write("<br>");
		document.write(elements[i][2]);
		document.write("<br>");
	}

// Rest of code is after this
The problem I run into is this: It does exactly what I want it to do, stores the data to an array and prints it exactly how I want it, however it does not seem to either exit the for loop or something weird, as the rest of the script will not run, and in firefox it prints my dad then sits there saying "Loading..." with the circle spinning.

When i comment out that entire for loop the rest of the script will run, so I have to assume it has something to do with that. Anyone have any suggestions?
mynameisdave145 is offline   Reply With Quote
Old 10-17-2006, 06:20 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Where is xmlDoc defined? What is it?
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 10-17-2006, 06:44 PM   PM User | #3
mynameisdave145
New Coder

 
Join Date: Oct 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
mynameisdave145 is an unknown quantity at this point
xmlDoc info:
Code:
<script type="text/javascript">
var xmlDoc;
function loadXML()
{
// code for IE
if (window.ActiveXObject)
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.load("glossary.xml");
  getmessage();
  }
// code for Mozilla & other browsers
else{
  xmlDoc=document.implementation.createDocument("","",null);
  xmlDoc.load("glossary.xml");
  xmlDoc.onload=getmessage;
  }
}
mynameisdave145 is offline   Reply With Quote
Old 10-18-2006, 04:25 PM   PM User | #4
mynameisdave145
New Coder

 
Join Date: Oct 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
mynameisdave145 is an unknown quantity at this point
anyone have any ideas?
mynameisdave145 is offline   Reply With Quote
Old 10-24-2006, 05:38 PM   PM User | #5
mynameisdave145
New Coder

 
Join Date: Oct 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
mynameisdave145 is an unknown quantity at this point
I am still stuck here. If anyone has any ideas or suggestions for me to try that would be very helpful. Here is my full code:

Code:
<script type="text/javascript">
var xmlDoc;
//Elements plaecholder
var elements = new Array();
function loadXML()
{
// code for IE
if (window.ActiveXObject)
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.load("glossary.xml");
  getmessage();
  }
// code for Mozilla & other browsers
else{
  xmlDoc=document.implementation.createDocument("","",null);
  xmlDoc.load("glossary.xml");
  xmlDoc.onload=getmessage;
  }
}

function getmessage()
{
//Get list of definition tags
var glossary = xmlDoc.getElementsByTagName('definition');
//document.write(glossary.length); //Test length of glossary in words

//Using length of glossary, put information into elements placeholder
	for (i=0;i<glossary.length;i++)
	{
		// Get words and put them into first element of array
		var word_length = xmlDoc.getElementsByTagName("word");
		var word = word_length[i].childNodes[0].nodeValue;
		 	//document.write(word);
		elements[i] = new Array(word);
		//	document.write(elements[i][0]);

		//Get sections and put them into the second element of array
		var section_length = xmlDoc.getElementsByTagName("section");
		var section = section_length[i].childNodes[0].nodeValue;
		elements[i][1] = section;

		//Get definitions and put them into third element of array
		var def_length = xmlDoc.getElementsByTagName("def");
		var def = def_length[i].childNodes[0].nodeValue;
		elements[i][2] = def;

		document.write(elements[i][0]);
		document.write("<br>");
		document.write(elements[i][1]);
		document.write("<br>");
		document.write(elements[i][2]);
		document.write("<br>");
	}

/////////////////////////////////////////////////////////////////////////

	var words = new Array();
	var word_count = 0;

	var arrElements = document.getElementsByTagName('span');
	for (i=0;i<arrElements.length;i++)
	{
		if(arrElements[i].className == "word")
		{
			words[word_count] = arrElements[i].firstChild.nodeValue;
			//alert(words[word_count]);
			word_count++;
		}
	}

}
  </script>

Last edited by mynameisdave145; 10-24-2006 at 05:45 PM..
mynameisdave145 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 11:06 PM.


Advertisement
Log in to turn off these ads.