// change log // created: 2021-05-09 //populates the drop down dropDownIdToPopulate on selecting a value in drop down selectedItemId function populateDropDown(selectedItemId, dropDownIdToPopulate, populateVendorCities){ document.getElementById(dropDownIdToPopulate).style.display = 'none'; //create the http request checking for mozilla vs ie if (window.XMLHttpRequest) { httpRequest = new XMLHttpRequest(); if (httpRequest.overrideMimeType) { httpRequest.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } //make sure the request was created properly if (!httpRequest) { //changed to return true so that the form proceeds return true; } selectedItem = document.getElementById(selectedItemId); //set our call back function to be called once the info is processed httpRequest.onreadystatechange = function() { startPopulatingWithSelect(httpRequest, dropDownIdToPopulate); }; //query string '&popVenCts' will get cities the vendor have registered or else, get all the cities for the region populateCities = ''; if(populateVendorCities == 1){ populateCities = '&popVenCts'; } //make the url to be called var url = 'getCities.php?rid=' + escape(selectedItem.options[selectedItem.selectedIndex].value) + populateCities; try { httpRequest.open('GET', url, true); } catch(e) { //if there is any kind of error opening the request we will return true so that the form submits via normal http return true; } //headers httpRequest.setRequestHeader("Connection", "close"); //send the request httpRequest.send(null); //set the return to false so that the form is not submitted via html return false; } //populates the drop down box dropDownIdToPopulate from the xml elements in httpRequest function startPopulatingWithSelect(httpRequest, dropDownIdToPopulate){ if (httpRequest.readyState == 4) { if (httpRequest.status == 200) { //for debugging uncomment the following line var xmldoc = httpRequest.responseXML; var cities = xmldoc.getElementsByTagName('cities').item(0); //get the drop down box element by its id mainCitySelect = document.getElementById(dropDownIdToPopulate); //clearing the currently listed cities cityCount = mainCitySelect.length; if (cityCount > 0){ for (var i=cityCount; i > 0; i--){ mainCitySelect.options[i] = null; } } //adding the cities to the drop down box for(var i=0; i < cities.childNodes.length; i++){ var cityId = cities.childNodes[i].getAttribute('id'); var cityName = cities.childNodes[i].firstChild.data; //adding the returned cities to the city select box mainCitySelect.options[(i + 1)] = new Option(cityName, cityId); } document.getElementById(dropDownIdToPopulate).style.display = 'block'; } } }