/    Sign up×
Community /Pin to ProfileBookmark

trying to unhide div with xml file variable

Hi

I’ve got a little bit of ajax happening that gets a mails “read” status from a mysql database. I’m then exporting an xml file of the data to read back in with javascript.

This bit all seems to be fine. The problem i’m having is with the imported xml data i need to hide or unhide a div

i’ve got divs on the page that look like
<div id=’readMail39′ style=’display:none’>

the javascript code i’ve got is

[code]
var mId = xmlDoc.getElementsByTagName(“email”) //<< MAIL ID AND STATUS
var numMails = xmlDoc.getElementsByTagName(’email’).length //NUMBER OF EMAILS
var mNum;

for (i=0;i<numMails;i++)
{
mNum = mId[1].childNodes[0].nodeValue;

if (mId[i].childNodes[1].lastChild.nodeValue == 0)
{
document.getElementById(‘readMail’+mNum).style.display = ‘none’;
document.getElementById(‘unreadMail’+mNum).style.display = ‘block’;
}
else
{
document.getElementById(‘readMail’+mNum).style.display = ‘block’;
document.getElementById(‘unreadMail’+mNum).style.display = ‘none’;
}
}
[/code]

i think it’s the “mNum” variable that keeps messing things up as i keep getting the error:

Error: document.getElementById(“readMail” + mNum) has no properties

if i try and cheat it however by just changing to display =’block’ line to

document.getElementById(‘readMail39’).style.display = ‘block’;

it works fine. what am i getting so wrong????
my xml is

[code]
<mail>
<email>
40
<status>1</status>
</email>
<email>
38
<status>0</status>
</email>
<email>
39
<status>0</status>
</email>
<email>
41
<status>1</status>
</email>
</mail>
[/code]

any ideas on this would be amazing
Thank you

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@cshelswellauthorMay 22.2007 — SOLVED!!

This took a while - i just needed to parse it as an integer ?

mNum = mId[i].childNodes[0].nodeValue;

pointValue_n = parseInt(mNum,10);
×

Success!

Help @cshelswell 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.16,
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,
)...