Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh page with select list

Status
Not open for further replies.

dpalmond

Programmer
Jul 3, 2007
5
US
I have a page that has 3 select list that are loaded from xml files with the following code:

var xmlObj1 = new XML("xml/esf_data1.xml");
var xmlObj2 = new XML("xml/esf_data2.xml");

xmlObj1.onLoad = function() {
}

xmlObj2.onLoad = function() {
populateDivisionList();
populateFacilityList();
populateOriginatorList();
}

function populateDivisionList() {
clearSelect(document.statusForm.OBDataset_Division_1);
var divisions = xmlObj1.data.firstChild.childNodes;
for(var i = 0; i < divisions.length; i++) {
var value = divisions.attributes.getNamedItem("id").nodeValue;
document.statusForm.OBDataset_Division_1.options = new Option(value, value, false, false);
}
}

function populateFacilityList() {
clearSelect(document.statusForm.OBDataset_Facility_1);
var divisionName = document.statusForm.OBDataset_Division_1.options[document.statusForm.OBDataset_Division_1.selectedIndex].value;
var facilities = findDivision(divisionName);
for(var i = 0; i < facilities.length; i++) {
var value = facilities.attributes.getNamedItem("id").nodeValue;
document.statusForm.OBDataset_Facility_1.options = new Option(value, value, false, false);
}populateOriginatorList()
}

function populateOriginatorList() {
clearSelect(document.statusForm.OBDataset_Originator_1);
var facilityName = document.statusForm.OBDataset_Facility_1.options[document.statusForm.OBDataset_Facility_1.selectedIndex].value;
var originators = findFacility(facilityName);
for(var i = 0; i < originators.length; i++) {
var value = originators.attributes.getNamedItem("id").nodeValue;
document.statusForm.OBDataset_Originator_1.options = new Option(value, value, false, false);
}
}

function findDivision(divisionName) {
var divisions = xmlObj1.data.firstChild.childNodes;
for(var i = 0; i < divisions.length; i++) {
if(divisions.attributes.getNamedItem("id").nodeValue == divisionName) {
return divisions.childNodes;
}
}
}

function findFacility(facilityName) {
var facilities = xmlObj2.data.firstChild.childNodes;
for(var i = 0; i < facilities.length; i++) {
if(facilities.attributes.getNamedItem("id").nodeValue == facilityName) {
return facilities.childNodes;
}
}
}

function clearSelect(list) {
for(var i = 0; i < list.options.length; i++) {
list.options = null;
}
}

When I do a refresh of the page the select list will not reload. Does anyon know how I can get the select list to reload when the page refreshes?
 
You could set up an onload event on the window objject that calls the functions to initiate the XML loading. Something like this:

Code:
window.onload = function() {
   // call your code here
}

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Dan,

I was able to fix the problem with the following function:
function refresh_Form()
{
statusForm.reset();

populateDivisionList();
populateFacilityList();
populateOriginatorList();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top