/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] function will not work if another function is called first

the following code showFeb() will work unless I call showJan() first. the error message I get is “title is null.” I have tried calling getData() again in the function but that didn’t work either.

Any help will be appreciated.

[CODE]function getData(dataSource, divID) {
var mozillaFlag = false;
var XMLHttpRequestObject = false; //create XMLHttpRequest object

if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
mozillaFlag = true;
}
else if (window.ActiveXObject) {
XMLHttpRequestObject = new
ActiveXObject (“Microsoft.XMLHTTP”);
} // end XMLHttpRequest object

if (XMLHttpRequestObject) { //download the data
var obj = document.getElementById(divID);
XMLHttpRequestObject.open(“GET”, dataSource);

XMLHttpRequestObject.onreadystatechange = function() {
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // got the data
obj = XMLHttpRequestObject.responseXML;
loadNodes(obj); //passes source XML document to displayBusinesses function in variable xmlDocument
}
}
XMLHttpRequestObject.send(null);
}
}
function loadNodes(calObj) {
calendarNode = calObj.getElementsByTagName(“calendar”);
monthNode = calObj.getElementsByTagName(“month”);
eventStartNode = calObj.getElementsByTagName(“eventStart”);
eventEndNode = calObj.getElementsByTagName(“eventEnd”);
eventNameNode = calObj.getElementsByTagName(“eventName”);
locationNode = calObj.getElementsByTagName(“location”);
detailsNode = calObj.getElementsByTagName(“details”);
phoneNode = calObj.getElementsByTagName(“phone”);
webNode = calObj.getElementsByTagName(“web”);
}
function showJan(){
var temp = document.getElementById(“events”);
temp.innerHTML = “sorry no events for Janurary”;
}
function showDetails() {
//get value of each eventName nodes and add link to the details
}
function showFeb() {
var debug = document.getElementById(“eventDetails”);
var counter;
var showEvents = [];
var title = document.getElementById(“eventsTitle”);
title.innerHTML = “February Calendar Events”;
var div = document.getElementById(“eventsBody”);
div.innerHTML = ” “;
for (counter=0; counter < monthNode.length; counter++) {
if (monthNode[counter].firstChild.nodeValue.match(“February”)) {
showEvents = eventNameNode[counter].firstChild.nodeValue;
var newDiv = document.createElement(“div”);
var newText = document.createTextNode(showEvents);
newDiv.appendChild(newText);
div.appendChild(newDiv);
}
//debug.innerHTML = eventNameNode[counter].firstChild.nodeValue;
}
}
[/CODE]

[code=html]<body onload=”getData(‘xmlData/calendar.xml’)”>
[/code]

[URL=”http://davispubs.com/westbycoc/calendar.html”][/URL]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@kaiser0427authorJan 13.2009 — I have resolved this issue with the following code.

[CODE]function showJan(){
var title = document.getElementById("eventsTitle");
title.innerHTML = "Janurary Calendar Events";
var eventsBody = document.getElementById("eventsBody");
eventsBody.innerHTML = "sorry no events for Janurary";
}
function showDetails() {
//get value of each eventName nodes and add link to the details instance of "a"
}
function showFeb() {
var debug = document.getElementById("eventDetails");
var counter;
var showEvents = [];
var title = document.getElementById("eventsTitle");
title.innerHTML = "February Calendar Events";
var div = document.getElementById("eventsBody");
div.innerHTML = " ";
for (counter=0; counter < monthNode.length; counter++) {
if (monthNode[counter].firstChild.nodeValue.match("February")) {
showEvents = eventNameNode[counter].firstChild.nodeValue;
var newDiv = document.createElement("div");
var newText = document.createTextNode(showEvents);
newDiv.appendChild(newText);
div.appendChild(newDiv);
}
debug.innerHTML = eventNameNode[counter].firstChild.nodeValue;
}
}

[/CODE]
×

Success!

Help @kaiser0427 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...