www.webdeveloper.com
Results 1 to 2 of 2

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

  1. #1
    Join Date
    Jan 2009
    Location
    Ixonia, WI
    Posts
    56

    resolved [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; 
    	}
    }
    HTML Code:
    <body onload="getData('xmlData/calendar.xml')">

  2. #2
    Join Date
    Jan 2009
    Location
    Ixonia, WI
    Posts
    56
    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; 
    	}
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles