/    Sign up×
Community /Pin to ProfileBookmark

Generating Javascript/XML Table

Hello to all. I am in the process of writing a script that will dynamically generate a table using javascript and XML. I can get all of my data to feed in with no problem but am getting hung up on a few small syntax issues.

Basically I need to assign a unique id equal to [i] (instead of id=”answerDiv”, in bold below) so that when calling showHide() it will show/hide one specific div.

Current Table Script

[CODE]//table 2
document.write(“<table id=’tbl2′ cellpadding=’0′ cellspacing=’0′ border=’0′ style=’display: none; width:236px;’>”);
var x=xmlDoc.getElementsByTagName(“feature”);
for (i=0;i<x.length;i++)
{
document.write(“<tr><td class=’eventDate’>”);document.write(x[i].getElementsByTagName(“question”)[0].childNodes[0].nodeValue);
document.write(“</td><td class=’eventText’>”);
document.write(x[i].getElementsByTagName(“content”)[0].childNodes[0].nodeValue);
document.write(‘<a href=”#” class=”redLink triviaAnswer” onclick=”showHide();”>click for answer</a><br><br>
<div [B]id=”answerDiv”[/B] style=”display:none”>’);
document.write(x[i].getElementsByTagName(“answer”)[0].childNodes[0].nodeValue);
document.write(‘</div></td></tr><tr><td colspan=”3″><div class=”tabs_hr”></div></td></tr>’);
}
document.write(“</table>”);[/CODE]

Show/Hide Function

[CODE]function showHide(){
var answer = document.getElementById(‘answerDiv’);
if(document.getElementById(‘answerDiv’).style.display == ‘none’)
{
answer.style.display = “block”;
}
else
{
answer.style.display = “none”;
}
}[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@negreljaauthorJan 06.2011 — sorry for posting thread twice, it wasn't showing up for me the first time.
×

Success!

Help @negrelja 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.19,
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,
)...