How to call a looping array instead of 5 individual pulls
Greetings All,
I've been advised to utilize an array system to acquire the data I am pulling from an XML document, but the only way I've currently gotten it to work is by calling 5 different instances of the same code. I would really appreciate help simplifying this code by calling a loop of 5 times for pulling posts and information on how to store it into an array so I can call back on it in my other code.
EDIT: It doesn't pull the same data that it was pulling before and no posts show up now. It's as if it's not gathering the array correctly (or posting it onto the page)
Last edited by sinsysonline; 12-07-2012 at 07:13 PM..
var i=0,d;
while (d=document.getElementById["Body"+i])
d.innerHTML=xmlDoc.getElementsByTagName("Body")[i++].childNodes << I wouldn't split the line here
[0].nodeValue;
Code:
var i='',d;
while (d=document.getElementById["Body"+i]) {
if (i === '') i = 0;
d.innerHTML=xmlDoc.getElementsByTagName("Body")[i++].childNodes[0].nodeValue;
}
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
I think he is going to have to learn to use a debugger. It's amazing how much time people will waste because they won't take the 20 to 30 minutes that is needed to learn to use a debugger.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Thanks Old Pendant. The condescation is a bit unnecessary as I'm FREQUENTLY in your position where I get frustrated that people don't do their research.
This is one of the first times I've literally WROTE my code instead of just modifying existing snippets, but I appreciate your support with helping me understand the concept.
I assure you, a debugger is definitely my next step. This is a project I'm doing with a timeline and although I have it working (although very sloppy and not properly coded) I'm simply trying to expand my grasp on the concept.
In any event, any replies, even if they are advice on tools to use are greatly appreciated.
I'll take all of the feedback here and figure it out on Monday and post any results I get. Thanks for all of the support!
Trust me, you are far and way NOT the first or only person who has come here for help that we can't really give because we don't have access to your site. If you could give us a publicly accessible URL, then we could probably find the bug in minutes, using a debugger.
But when you have a private site, then the only real answer is to learn to use a debugger, and that's neither condescension nor frustration. It's simply the truth.
Honest, if you would spend 20 to 30 minutes--maybe less--leaning to use a debugger, you would be able to figure this out in minutes yourself, more than llikely.
My own preference nowadays is for the Chrome debugger. They are all pretty much the same, but Chrome has a few features the others don't. Its biggest plus is that you can pull it up at any time and see the errors on the current page *and* set breakpoints on the current page without having to refresh the page. Neither Firebug for the FireFox browser nor the MSIE browser can do that. They make you at least refresh the page before you can do anything.
And it's so easy to use: Just hit the F12 key and wham, there it is. If you have multiple files making up your page, there's an easy to use drop-down list on the SOURCES tab that allows you to pick the one you want to debug (e.g., a ".js" file,, or the main page itself).
On the right side, all your currently available JS variables are neatly grouped (Global, Local, and Scope variables).
Or set a breakpoint any where in your JS code (by simply clicking to the left of the line of code in the "Sources" pane) and, when it is reached, hover over any variable in the displayed JS code to find its value. Even hover over sxpressions. (For example, if your code has something like xmlDoc.getElementsByTagName("Body")[i++].childNodes[0].nodeValue you can hover over most any part of that. If you hovered over childNodes you'd see a list of all such nodes. And more.)
Honest, you can learn the basics of the debugger in a few minutes and save yourself HOURS. Save yourself hours the first time you don't have to wait for an answer in the forum, for example.
I really do encourage you--and anybody else reading this--to at least try using a debugger. If that still doesn't help...well, then it's for sure time to post here.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.