// XMLHTTP Request object var XmlHttpObj; var boxSelezionato; // Crea un'istanza di XMLHTTPRequest Object diversificata in base al browser (Mozilla, IE) function CreateXmlHttpObj() { // si tenta di creare l'instanza per IE try { XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(oc) { XmlHttpObj = null; } } // se la creazione per IE non riesce si crea per Mozilla if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") { XmlHttpObj = new XMLHttpRequest(); } } // funzione chiamata dall'OnChange nella DropDownl List function OnChange() { boxSelezionato = "1"; var List = document.getElementById("tipo"); // Ottiene l'elemento selezionato nella dropdown var selectedItem = List.options[List.selectedIndex].value; // Url della pagina che risponderà con il flusso XML var requestUrl; requestUrl = 'http://www.francorosso.it/cache/GetCache_drp1.asp' + '?filter=' + encodeURIComponent(selectedItem); CreateXmlHttpObj(); // verifica che la variabile XmlHttpObj sia inizializzata if(XmlHttpObj) { // assign the StateChangeHandler function ( defined below in this file) // to be called when the state of the XmlHttpObj changes // receiving data back from the server is one such change XmlHttpObj.onreadystatechange = StateChangeHandler; // define the iteraction with the server -- true for as asynchronous. XmlHttpObj.open("GET", requestUrl, true); // send request to server, null arg when using "GET" if (encodeURIComponent(selectedItem) != '') { XmlHttpObj.send(null); } } } function OnChange2() { boxSelezionato = "2"; var List1 = document.getElementById("tipo"); var List2 = document.getElementById("dest2"); // Ottiene l'elemento selezionato nella dropdown var selectedItem1 = List1.options[List1.selectedIndex].value; var selectedItem2 = List2.options[List2.selectedIndex].value; // Url della pagina che risponderà con il flusso XML var requestUrl; requestUrl = "http://www.francorosso.it/cache/GetCache_drp2.asp" + "?filter1=" + encodeURIComponent(selectedItem1) + "&filter2=" + encodeURIComponent(selectedItem2); CreateXmlHttpObj(); // verifica che la variabile XmlHttpObj sia inizializzata if(XmlHttpObj) { // assign the StateChangeHandler function ( defined below in this file) // to be called when the state of the XmlHttpObj changes // receiving data back from the server is one such change XmlHttpObj.onreadystatechange = StateChangeHandler; // define the iteraction with the server -- true for as asynchronous. XmlHttpObj.open("GET", requestUrl, true); // send request to server, null arg when using "GET" if (encodeURIComponent(selectedItem2) != '') { XmlHttpObj.send(null); } } } // this function called when state of XmlHttpObj changes // we're interested in the state that indicates data has been // received from the server function StateChangeHandler() { // state ==4 indicates receiving response data from server is completed if(XmlHttpObj.readyState == 4) { // To make sure valid response is received from the server, 200 means response received is OK if(XmlHttpObj.status == 200) { PopulateCountryList(XmlHttpObj.responseXML.documentElement); } else { alert("problem retrieving data from the server, status code: " + XmlHttpObj.status); } } } // populate the contents of the country dropdown list function PopulateCountryList(countryNode) { var countryList var drpName if (boxSelezionato == "1") { countryList = document.getElementById("dest2"); drpName = "dest2" // for (var count = document.getElementById("dest2").options.length-1; count >-1; count--) { document.getElementById("dest2").options[count] = null; } for (var count = document.getElementById("destinazione").options.length-1; count >-1; count--) { document.getElementById("destinazione").options[count] = null; } // } else if (boxSelezionato == "2") { countryList = document.getElementById("destinazione"); drpName = "destinazione" // for (var count = document.getElementById("destinazione").options.length-1; count >-1; count--) { document.getElementById("destinazione").options[count] = null; } // } var idValue; var textValue; var countryNodes = countryNode.getElementsByTagName('dest'); // var opt1 = document.createElement("option"); opt1.text = "- Seleziona -"; opt1.value = ""; document.getElementById(drpName).options.add(opt1); // // Popola la dropdown for (var count = 0; count < countryNodes.length; count++) { var opt = document.createElement("option"); textValue = GetInnerText(countryNodes[count]); livValue = countryNodes[count].getAttribute("liv"); if (boxSelezionato == "1") { idValue = countryNodes[count].getAttribute("nam"); if (livValue == '1') { opt.style.color = '#94210f'; textValue = textValue.toUpperCase(); } else if (livValue == '2') { textValue = " " + textValue; } } else if (boxSelezionato == "2") { idValue = countryNodes[count].getAttribute("id"); if (livValue == '2') { opt.style.color = '#94210f'; textValue = textValue.toUpperCase(); } if (livValue == '3') { textValue = " " + textValue.toUpperCase(); } if (livValue == '4') { textValue = " " + textValue; } } // opt.text = textValue opt.value = idValue // document.getElementById(drpName).options.add(opt); } } // returns the node text value function GetInnerText (node) { return (node.textContent || node.innerText || node.text) ; }