ragazzi, ho trovato uno script interessante che sto modificando (sarà faticoso caricare le città e i comuni italiani, ma è fattibile
), ma ho un problema se devo inserire una seconda coppia di menu a tendina. Ecco gli script:
index.html
codice:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="aspetto/cuntry.js"></script>
</head>
<body onLoad="Fill_Country(); ">
<table >
<form name="form1" method="get" action="visualizza.php">
<tr>
<td class="latoTrasp" >Country 1:</td>
<td><select name="cboCountry" style="width:auto;clear:none;" onChange="Fill_States();">
<option></option></select></td>
</tr>
<tr>
<td class="latoTrasp" >State 1:</td>
<td><select name="cboState" style="width:auto;" onChange="Update_Globals();">
<option></option></select></td>
</tr>
</form>
</table>
<table >
<form name="form2" method="get" action="menu.php">
<tr>
<td class="latoTrasp" >Country 2:</td>
<td><select name="cboCountry2" style="width:auto;clear:none;" onChange="Fill_States();">
<option></option></select></td>
</tr>
<tr>
<td class="latoTrasp" >State 2:</td>
<td><select name="cboState2" style="width:auto;" onChange="Update_Globals();">
<option></option></select></td>
</tr>
</form>
</table>
</body>
</html>
country.js
codice:
//<!--
var gLngMaxStateLength=0;
var gLngMaxCountryLength=0;
var gLngNumberCountries=252;
var gLngNumberStates=0;
var gLngSelectedCountry=0;
var gLngSelectedState=0;
var gArCountryInfo;
var gArStateInfo;
// NOTE:
// Some editors may exhibit problems viewing 2803 characters...
var sCountryString = "|Afghanistan|Albania|Algeria|American Samoa|Angola|Anguilla|Antartica|Antigua and Barbuda|Argentina|Armenia|Aruba|Ashmore and Cartier Island|Australia|Austria|Azerbaijan|Bahamas|Bahrain|Bangladesh|Barbados|Belarus|Belgium|Belize|Benin|Bermuda|Bhutan|Bolivia|Bosnia and Herzegovina|Botswana|Brazil|British Virgin Islands|Brunei|Bulgaria|Burkina Faso|Burma|Burundi|Cambodia|Cameroon|Canada|Cape Verde|Cayman Islands|Central African Republic|Chad|Chile|China|Christmas Island|Clipperton Island|Cocos (Keeling) Islands|Colombia|Comoros|Congo, Democratic Republic of the|Congo, Republic of the|Cook Islands|Costa Rica|Cote d'Ivoire|Croatia|Cuba|Cyprus|Czeck Republic|Denmark|Djibouti|Dominica|Dominican Republic|Ecuador|Egypt|El Salvador|Equatorial Guinea|Eritrea|Estonia|Ethiopia|Europa Island|Falkland Islands (Islas Malvinas)|Faroe Islands|Fiji|Finland|France|French Guiana|French Polynesia|French Southern and Antarctic Lands|Gabon|Gambia, The|Gaza Strip|Georgia|Germany|Ghana|Gibraltar|Glorioso Islands|Greece|Greenland|Grenada|Guadeloupe|Guam|Guatemala|Guernsey|Guinea|Guinea-Bissau|Guyana|Haiti|Heard Island and McDonald Islands|Holy See (Vatican City)|Honduras|Hong Kong|Howland Island|Hungary|Iceland|India|Indonesia|Iran|Iraq|Ireland|Ireland, Northern|Israel|Italy|Jamaica|Jan Mayen|Japan|Jarvis Island|Jersey|Johnston Atoll|Jordan|Juan de Nova Island|Kazakhstan|Kenya|Kiribati|Korea, North|Korea, South|Kuwait|Kyrgyzstan|Laos|Latvia|Lebanon|Lesotho|Liberia|Libya|Liechtenstein|Lithuania|Luxembourg|Macau|Macedonia, Former Yugoslav Republic of|Madagascar|Malawi|Malaysia|Maldives|Mali|Malta|Man, Isle of|Marshall Islands|Martinique|Mauritania|Mauritius|Mayotte|Mexico|Micronesia, Federated States of|Midway Islands|Moldova|Monaco|Mongolia|Montserrat|Morocco|Mozambique|Namibia|Nauru|Nepal|Netherlands|Netherlands Antilles|New Caledonia|New Zealand|Nicaragua|Niger|Nigeria|Niue|Norfolk Island|Northern Mariana Islands|Norway|Oman|Pakistan|Palau|Panama|Papua New Guinea|Paraguay|Peru|Philippines|Pitcaim Islands|Poland|Portugal|Puerto Rico|Qatar|Reunion|Romainia|Russia|Rwanda|Saint Helena|Saint Kitts and Nevis|Saint Lucia|Saint Pierre and Miquelon|Saint Vincent and the Grenadines|Samoa|San Marino|Sao Tome and Principe|Saudi Arabia|Scotland|Senegal|Seychelles|Sierra Leone|Singapore|Slovakia|Slovenia|Solomon Islands|Somalia|South Africa|South Georgia and South Sandwich Islands|Spain|Spratly Islands|Sri Lanka|Sudan|Suriname|Svalbard|Swaziland|Sweden|Switzerland|Syria|Taiwan|Tajikistan|Tanzania|Thailand|Tobago|Toga|Tokelau|Tonga|Trinidad|Tunisia|Turkey|Turkmenistan|Tuvalu|Uganda|Ukraine|United Arab Emirates|United Kingdom|Uruguay|USA|Uzbekistan|Vanuatu|Venezuela|Vietnam|Virgin Islands|Wales|Wallis and Futuna|West Bank|Western Sahara|Yemen|Yugoslavia|Zambia|Zimbabwe";
var aStates = new Array();
aStates[0]="";
aStates[1]="Badakhshan|Badghis|Baghlan|Balkh|Bamian|Farah|Faryab|Ghazni|Ghowr|Helmand|Herat|Jowzjan|Kabol|Kandahar|Kapisa|Konar|Kondoz|Laghman|Lowgar|Nangarhar|Nimruz|Oruzgan|Paktia|Paktika|Parvan|Samangan|Sar-e Pol|Takhar|Vardak|Zabol";
aStates[2]="Berat|Bulqize|Delvine|Devoll (Bilisht)|Diber (Peshkopi)|Durres|Elbasan|Fier|Gjirokaster|Gramsh|Has (Krume)|Kavaje|Kolonje (Erseke)|Korce|Kruje|Kucove|Kukes|Kurbin|Lezhe|Librazhd|Lushnje|Malesi e Madhe (Koplik)|Mallakaster (Ballsh)|Mat (Burrel)|Mirdite (Rreshen)|Peqin|Permet|Pogradec|Puke|Sarande|Shkoder|Skrapar (Corovode)|Tepelene|Tirane (Tirana)|Tirane (Tirana)|Tropoje (Bajram Curri)|Vlore";
//......ecc ecc.....
aStates[252]="Bulawayo|Harare|ManicalandMashonaland Central|Mashonaland East|Mashonaland West|Masvingo|Matabeleland North|Matabeleland South|Midlands";
/*
* gArCountryInfo
* (0) Country name
* (1) Name length
* (2) Number of states
* (3) Max state length
*/
gLngNumberCountries = sCountryString.split("|").length;
//gArCountryInfo = new Array(gLngNumberCountries);
gArCountryInfo=sCountryString.split("|");
/*
* gArStateInfo[country][statenames][namelengths]
* (0) Country
* (1) States (Multi-sized Array)
* (0) name
* (1) nameLength
*/
gArStateInfo = new Array(gLngNumberCountries);
/*
* fInitgArStateInfo()
* purpose: build gArStateInfo array
* gArStateInfo[Country][States][1]
* (0) State name
* (1) State name length
* gArStateInfo[i] is an array of state names
* gArStateInfo[i][j]=state name, name length
*/
function fInitgArStateInfo()
{
var i=0, j=0, sStateName="", iNumberOfStates=0;
var iMaxLength=0, iLength=0;
var oldNumber=0;
for (i=0;i<gLngNumberCountries;i++)
{
// i is selected country
iNumberOfStates=aStates[i].split("|").length+1;
gLngNumberStates=gLngNumberStates+iNumberOfStates;
gArStateInfo[i]=new Array(iNumberOfStates);
iMaxLength=0;
// Add the additional information
for (j=0;j<iNumberOfStates;j++)
{
if (iLength>iMaxLength)
{
iMaxLength=iLength;
gArStateInfo[i][j][0]=sStateName;
}
}
gArCountryInfo[i][3]=parseInt(iMaxLength);
}
Update_Globals();
return;
}
/*
* Working on this one.
* Fills in cboState from the arrays
*
*/
function xFillState()
{
var i=0;
// reset cboState
document.form1.cboState.options.length=0;
// get selected country
gLngSelectedCountry=document.form1.cboCountry.selectedIndex;
// get number of states for selected country
gLngNumberStates=gArCountryInfo[[gLngSelectedCountry][2]];
// update options in cboState
for (i=0;i<gLngNumberStates;i++)
{
document.form1.cboState.options[i]=new
Option(gArStateInfo[[gLngSelectedCountry][i][0]]);
}
gLngSelectedState=
document.form1.cboState.options.selectedIndex;
return;
}
/*
* FillStates() function works.
* Fills cboState from aStates
*/
function Fill_States()
{
var i=0, iLen=0, iNumStates=0;
// reset cboState
document.form1.cboState.options.length=0;
// get selected country
gLngSelectedCountry=document.form1.cboCountry.selectedIndex;
iNumStates = aStates[gLngSelectedCountry].split("|").length;
// update the text boxes
Update_Globals();
// file the state combobox with the list of states
for (i=0;i<iNumStates;i++)
{
document.form1.cboState.options[i]=new
Option(aStates[document.form1.cboCountry.selectedIndex].split("|")[i]);
}
updSelectState(0);
return;
}
/*
* FillCountry()
* gArCountryInfo matrix holds the following information:
* (0) Country name
* (1) Name length
* (2) Number of states
* (3) Max state length
*/
function Fill_Country()
{
var i=0;
var sCountryName="";
// reset cboCountry.options
document.form1.cboCountry.options.length=0;
// get number of countries from the string
// ----------------------------------------------------
// gArCountryInfo = new Array(gLngNumberCountries, 4);
// ----------------------------------------------------
for (i=0;i<gLngNumberCountries;i++)
{
gArCountryInfo[i]=new Array(4);
}
for (i=0;i<gLngNumberCountries;i++)
{
document.form1.cboCountry.options[i]=new Option(sCountryString.split("|")[i]);
sCountryName=document.form1.cboCountry.options[i];
// gArCountryInfo[i][0]=sCountryName;
// gArCountryInfo[i][1]=sCountryName.length;
// gArCountryInfo[i][2]=aStates.split("|")[i].length;
// gArCountryInfo[i][3]=0;
gArCountryInfo[i]=
[sCountryName,
parseInt(sCountryName.length),
aStates,
0];
}
fInitgArStateInfo();
return;
}
function updSelectState(lngState)
{
if (gLngSelectedCountry>0)
{
document.form1.cboState.selectedIndex = lngState;
}
}
/*
* gArCountryInfo matrix holds the following information:
* (0) Country name
* (1) Name length
* (2) Number of states
* (3) Max state length
*/
function Update_Globals()
{
gLngSelectedCountry=parseInt(document.form1.cboCountry.selectedIndex);
gLngSelectedState=parseInt(document.form1.cboState.selectedIndex);
return;
}
//-->
come si può modificare per fargli caricare anche il 2° form?