PDA

View Full Version : syntax question


firepages
12-22-2002, 02:05 PM
Hi, I am trying to iterate through an array and dynamically alter the contents of some <span></span>'s

to avoid doing this for each element..

C_TITLE.innerText=xmlDoc.getElementsByTagName("C_TITLE").item(current).text

that fills in the <span id="C_TITLE"></span> which works fine

I am currently trying this...


var bits=new Array('C_TITLE','C_NAME','C_SURNAME','C_EXPIRY','C_ENTITY','C_ADDRESS1','C_ADDRESS2','C_SUBURB','C_P OSTCODE','C_PHONE','C_PHONE2','C_MOBILE','C_FAX','C_EMAIL','C_WEBSITE','C_OCCUPATION');

for (var i in bits){
bits[i].innerText=xmlDoc.getElementsByTagName(bits[i]).item(current).text
}


which does not, I have tried eval()'ing the statment etc but to no avail, I am sure its just a syntax issue with the

bits[i].innerText bit but cant find the right way to do this (the getElementsByTagName(bits[i]) does not itself seem to be an issue)

please enlighten !

mordred
12-22-2002, 02:34 PM
document.all[bits[i]].innerText = //... etc.


Enlightened?

firepages
12-22-2002, 03:06 PM
incandescent!

thankyou that was driving me potty

Skyzyx
12-22-2002, 03:07 PM
Never use document.all(). Always use document.getElementsByTagName() (or document.getElementById()). document.all() is IE-specific, while document.getElementsByTagName() is cross-platform.

I'd also look at a couple other things...

bLen=bits.length; // This will allow for faster looping.

for (i=0; i <= bLen; i++)
{
// This should fill the document's SPAN with the XML document's data.
document.getElementsByTagName(bits[i]).innerText=xmlDoc.getElementsByTagName(bits[i]).item(current).text;
}


I haven't tested this, but it should work cross-platform and still do what it is that you want it to do.

firepages
12-22-2002, 03:37 PM
Hi Skyzyx
that did not work for me in IE5.5 , as it happens this wont be x-browser as the XML doc is loaded like so

xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

in this case I have control over the user-environment as its a user-administration page and only a handful of people are ever likely to see it (and they will be using IE for at least the near future)

I tried getElementById as well but no joy though that was a guess ;)

If anyone knows a x-browser method of loading an XML document and scrolling thought the content then I am all ears as I would much prefer that on principle but I can not find decent documentation for anything but IE stuff, and that mostly in VB ! ugh

Skyzyx
12-22-2002, 03:57 PM
http://www.codingforums.com/showthread.php?s=&threadid=10603

firepages
12-22-2002, 04:54 PM
cool - thats looking interesting, I dont want to get into writing for 2 browsers again but if its just the loading of the xml document and then I can continue as per normal then thats excellent

so I will have a play with that cheers...

actually am I right in thinking that with the importXML() function I can also load files at runtime ? - I ask as the only problem I am having is loading large datasets into memory, if I could split them up and page them that would be cool (except for searching but I have another plan for that)

as for why I am doing this - I am moving a previously client-side application to the serverside and the client does not like the refreshing required when 'flicking' though files.