Jump to content

Xml Navigator


lowededwookie

Recommended Posts

First I just want to say thank you for your awesome XML tutorial. I've been wanting to do this for ages but you've given me a clear and concise example of how to achieve this but I have a problem with the Navigation side.Your example worked perfectly but not how I need it to work.Instead of displaying the page information how do I get it to actually go to the Next or Previous articles on clicking on the page?I'm picking the answer lies where I've marked <-- I think this needs to be changed yeah????

function next(){if (i<x.length-1)  {  i++;  display(); <-- I think this needs to be changed yeah????  }}function previous(){if (i>0)  {  i--;  display(); <-- I think this needs to be changed yeah????  }}

That being said what do I change it to?Please note I have no real experience of using Javascript so I'm using all of this as learning as well so if you could provide full code instead of a line or so in order for me to learn and understand what's going on I will be eternally grateful.Thanks.

Link to comment
Share on other sites

Your two functions alone basically do nothing. If they were defined within another object that happens to have an "i" property, then maybe it would do something.Anyhow, I suggest you scrap what you're doing, and try JavaScript first for a few simpler things, until you understand how DOM works, and how JavaScript works. In particular, learn about how and when events fire, as this is the most troubling and confusing part of JavaScript.A few simple exercises you might want to try out to do on your own. They're REALLY simple if you've read the tutorial and have a DOM exploring tool such as the built in one in IE8 (accessible with the F12 key).1. Change the text inside a certain element.2. Alter the "href" of all anchors to something.3. Change the title of the page on a click of a button.4. On the click of a "div" element, replace the div with a newly created "div".5. Get the value from a certain text field (on the click of a certain button), and write the value in another element.And if you also want to use XML in HTML, you might also want to try to:1. Open a plain XML file with XMLHttpRequest(), and upon receiving, append its raw contents in a certain textarea.2. Open a file with XMLHttpRequest(), with the exact URI being specified from a certain text field. Do the same as above upon receiving.Also, you should also see PHP. PHP can also work with XML. If you're able to do it there, you'll easily be able to migrate it to JavaScript. Since PHP has a lot more detailed and friedlier error messages, it will be easier for you to actually get something running.

Link to comment
Share on other sites

While I'm new to Javascript and XML I kind of do understand what is going on. That's not my issue.What I'm having the problem with is working out how I do what I want to do.I'm modified the XML tutorial to create a UL for Title and Link and therefore create links with the title to the manually created documents that I have made. That was easy because like I said I understand what is going on.However, I want to be able to pull specific references from an XML file (so I'm thinking using IDs are needed) and use that XML record to generate content.I need to use Javascript and not PHP because my site sits on MobileMe and that doesn't allow me to use anything other than XML and Javascript.At the moment I do not need to write to an XML file just read.So essentially I need to workout for the Navigator script what record I'm currently in and therefore what the next and previous records are so this is why I'm leaning more and more to the requirement of IDs.I have been told that I should look into JQuery. Is this a good idea?

Link to comment
Share on other sites

Fine... what's in your display() function? Do you have

var i=0;

before those two functions?As far as jQuery goes, I'd avoid it for now if I were you.

Link to comment
Share on other sites

Actually I just realised the tutorial I was working from (http://www.w3schools.com/xml/tryit.asp?fil...ml_app_navigate) was actually doing what I was wanting in the first place. :)I was wanting to grab the fields TITLE and LINK and create a link from them which then created the next and previous buttons from position relative to the record. What the tutorial does is pull the TITLE, LINK, and TEXT fields from the XML file and displays it refreshing the DIV automatically. All I need to do now is put my document text between the TEXT field in my XML and the document reads properly.Thanks for your help anyway

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...