Jump to content

[SOLVED] trying to unhide div with xml file variable


c_shelswell

Recommended Posts

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

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';
	}
}

 

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

<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>

 

any ideas on this would be amazing

Thank you

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.