Hey all, cant figure something out. i feel its something so simple!
The task is:
using javascript, take the names of games in this php (http://newmedia.purchase.edu/~sburdi...game_names.php) and put them in a pull down menu.
Printable View
Hey all, cant figure something out. i feel its something so simple!
The task is:
using javascript, take the names of games in this php (http://newmedia.purchase.edu/~sburdi...game_names.php) and put them in a pull down menu.
You need to use AJAX to grab the XML file parse it and display it on your page
The xml file that you want to read from must be on the same domain as the file thats reading it, so if this file is called page.htm and is on mydomain.com the xml file must be on mydomain.com as well.
This reads the xml file and places the Game_Name from the XML into a listbox.
Code:
<select id="menu"></select>
<script language="javascript">
function createRequestObject()
{
var request_o; //declare the variable to hold the object.
var browser = navigator.appName; //find the browser name
if(browser == "Microsoft Internet Explorer"){
/* Create the object using MSIE's method */
request_o = new ActiveXObject("Microsoft.XMLHTTP");
}else{
/* Create the object using other browser's method */
request_o = new XMLHttpRequest();
}
return request_o; //return the object
}
function handleMenu()
{
try
{
if(http.readyState == 4){ //Finished loading the response
var nodes = http.responseXML;
alert(nodes.getElementsByTagName('Game').length);
for(i = 0; i < nodes.getElementsByTagName('Game').length; i++)
{
menuItem = document.createElement("option");
menuItem.appendChild(document.createTextNode(nodes.getElementsByTagName('Game_Name')[i].firstChild.data));
document.getElementById('menu').appendChild(menuItem);
}
}
}
catch(Exception)
{
}
}
var http = createRequestObject();
function getMenu()
{
try
{
http.open('get', 'game_names.xml');
http.onreadystatechange = handleMenu;
http.send(null);
}
catch(Exception)
{
http = createRequestObject();
getMenu();
}
}
getMenu();
</script>
thanks a lot. works fine