/    Sign up×
Community /Pin to ProfileBookmark

XML generated list menu and on click

HI,

im wondering if anyone can help me with my javascript. I download xml data from a remote source containing a username and a description field which i then put into a menu – showing a rounded list item for each username and description as shown:

username: description
username: description etc..

when one of the above list items is selected, it loads up the #view anchor page which will then go to display more information contained within the xml file.

My question is, how does the new page (anchor) know which option has been selected? I tried the code below using a function to write to a localStorage variable but, it seems to get overwritten each time it is printed to the screen – not each time it is clicked with the onclick event…

[code]
<script type=”text/javascript”>

function setTagview(z){
localStorage.tag = z;
}

</script>
<title>my app</title>
</head>
<body>

<!– main list view page –>
<div id=”home”>
<div class=”toolbar”>
<h1>my app</h1>

<script type=”text/javascript”>
var i=0;
document.write(“<ul class=’rounded’>”);
for (i=0; i<=x.length; i++){
var username = xmlDoc.getElementsByTagName(“username”)[i].childNodes[0].nodeValue;
var description = constrain(xmlDoc.getElementsByTagName(“description “)[i].childNodes[0].nodeValue, 20);

document.write(“<li class=’arrow’><a href=’#view’ onClick=’setTagview(” + i + “);’>” + username + “: ” + description + “</a></li>”);

}
document.write(“</ul>”);
</script>
</div>
[/code]

in an instance where 2 items are received from xml, setTagview should call setTagview(0) for the first item, and setTagview(1) for the second item – hence setting the localstorage variable in the method setTagview. However the above output when clicking each menu item individually shows that they both end up using ‘1’ i.e. the variable is set both times to 1, i.e. the first item with i = 0 is ignored and 1 is used instead, if that makes sense.

so does anyone know why that is happening? and is there any way around it?

Cheers!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@skeg0authorAug 24.2010 — Anyone? Or any ideas?
×

Success!

Help @skeg0 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...