I’m making a fairly simple site with a rant/blogging facility done in javascript.
I’m trying to get it to navigate through rants using previous and next buttons.
the basic structure of it looks like this (code has been trimmed)…
[CODE]function change_rant(dir)
{
switch (dir)
{
case “prev”: {rant_num–;} break;
case “next”: {rant_num++;} break;
}
document.rant.data = “rants/”+rant_num+”.txt”;
}
…
<a href=”javascript: change_rant(‘prev’)”>Previous Rant</a>
<a href=”javascript: change_rant(‘next’)”>Next Rant</a>
<script>
document.write(‘<iframe width=”750″ height=”300″ data=”rants/’+latest_rant_num+’.txt” name=”rant”></object>’);
</script>
Obviously, I’m trying to display a new text file (name with a number.txt eg 1.txt, 2.txt) containing the next/previous rant when the user clicks the next or previous link.
Problem is: It doesn’t work. The data attribute seems to be changed ( alert(document.rant.data) tells me that the rant number has been changed), but the new text file is not displayed.
I’ve also tried using an iframe instead of an object (and replacing ‘data’ with ‘src’).
I’m pretty much stumped… This method works fine for things like changing the src of an img tag…
I’m after 1) a way to get it working with iframes or objects, or 2) ideas about some other html/js based way of doing it.
Any help would be very much appreciated.?
Kefka