www.webdeveloper.com
Results 1 to 4 of 4

Thread: Option, options and Africa Cities list

  1. #1
    Join Date
    Nov 2009
    Posts
    109

    Unhappy Option, options and Africa Cities list

    I am writing a javascript software very big so I quote a passage where there is the error. I am trying to find it but I can not. Could you give me an help, please?

    prova_city.html

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    <script type="text/javascript" src="theData.js"></script>
    <script type="text/javascript" src="timeFunctions.js"></script>
    </head>
    <body onload="writeItAll(Africa_Cities_List,africa);">
    <form name="myForm" method="get" action="">
    <select name="africa">
    <option value=""> </option>
    </select>
    </form>
    </body>
    </html>
    theData.js

    Code:
     var Africa_Cities_List = new Array();
      Africa_Cities_List[0] = new CityObj("Abidjan", 0, No_DST, "ABI");
      Africa_Cities_List[1] = new CityObj("Accra", 0, No_DST, "ACC");
      Africa_Cities_List[2] = new CityObj("Addis Ababa", 3, No_DST, "ADA");
      Africa_Cities_List[3] = new CityObj("Algiers", 1, UK_Europe_DST, "ALJ");
      Africa_Cities_List[4] = new CityObj("Antananarivo", 3, No_DST, "ANT");
      Africa_Cities_List[5] = new CityObj("Bamako", 0, No_DST, "BAM");
      Africa_Cities_List[6] = new CityObj("Benin City", 1, No_DST, "BEN");
      Africa_Cities_List[7] = new CityObj("Bloemfontein", 2, No_DST, "BLO");
      Africa_Cities_List[8] = new CityObj("Cairo", 2, UK_Europe_DST, "CAI");
      Africa_Cities_List[9] = new CityObj("Cape Town", 2, No_DST, "CTC");
      Africa_Cities_List[10] = new CityObj("Dakar", 0, No_DST, "DAK");
      Africa_Cities_List[11] = new CityObj("Dar-Es-Salaam", 3, No_DST, "DAR");
      Africa_Cities_List[12] = new CityObj("Durban", 2, No_DST, "DUR");
      Africa_Cities_List[13] = new CityObj("Freetown", 0, No_DST, "FRE");
      Africa_Cities_List[14] = new CityObj("Harare", 2, No_DST, "HAR");
      Africa_Cities_List[15] = new CityObj("Johannesburg", 2, No_DST, "JOH");
      Africa_Cities_List[16] = new CityObj("Kampala", 3, No_DST, "KAM");
      Africa_Cities_List[17] = new CityObj("Khartoum", 2, No_DST, "KAR");
      Africa_Cities_List[18] = new CityObj("Kinshasa", 1, No_DST, "KIN");
      Africa_Cities_List[19] = new CityObj("Luanda", 2, No_DST, "LUA");
      Africa_Cities_List[20] = new CityObj("Maputo", 2, No_DST, "MAP");
      Africa_Cities_List[21] = new CityObj("Mbala", 2, No_DST, "MBA");
      Africa_Cities_List[22] = new CityObj("Monrovia", 0, No_DST, "MON");
      Africa_Cities_List[23] = new CityObj("Ndjamena", 1, No_DST, "NDJ");
      Africa_Cities_List[24] = new CityObj("Pointe Noire", 1, No_DST, "PNO");
      Africa_Cities_List[25] = new CityObj("Port Elizabeth", 2, No_DST, "POE");
      Africa_Cities_List[26] = new CityObj("Pretoria", 2, No_DST, "PRE");
      Africa_Cities_List[27] = new CityObj("Rabat", 0, No_DST, "RBT");
      Africa_Cities_List[28] = new CityObj("Tripoli", 1, No_DST, "TRI");
      Africa_Cities_List[29] = new CityObj("Tsumeb", 2, No_DST, "TSU");
    timeFunctions.js

    Code:
    function CityObj(cityName, cityOffset, cityDST, cityAcronym) {
     this.cityName = cityName;
     this.cityOffset = cityOffset;
     this.cityDST = cityDST;
     this.cityAcronym = cityAcronym;
    }
    function writeItAll(theCityArray,continente) {
       var array_city = new Array(theCityArray.length+1);
       array_city[0]= new Option("&lt; Scegli citt&aacute; &gt;","&lt; Scegli citt&aacute; &gt;");
       for(var j=1; j < array_city.length+1; j++)
       {array_city[j] = new Option(theCityArray[j].cityName,theCityArray[j].cityAcronym);}
       for(var i=0; i < array_city.length+1; i++)
       {document.forms[0].continente.options[i] = array_city[i];}
    }
    I don't understand because it doesn't work. I can not move Africa_Cities_List variable and CityObj function from the files. I think that the problem is writeItAll but I am not sure.

    See you

    Marco

    Thanks for your help!
    Last edited by esacerbare; 12-27-2009 at 09:08 AM.

  2. #2
    Join Date
    Jul 2005
    Location
    Tangerang, Indonesia
    Posts
    171
    This is my version

    prova_city.html
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Documento senza titolo</title>
    <script type="text/javascript" src="timeFunctions.js"></script>
    <script type="text/javascript" src="theData.js"></script>
    </head>
    <body onload="writeItAll(Africa_Cities_List,'africa');">
    <form name="myForm" method="get" action="">
    <select name="africa">
    <option value=""> </option>
    </select>
    </form>
    </body>
    </html>
    theData.js
    Code:
    var No_DST="";
    var UK_Europe_DST = "";
    var Africa_Cities_List = new Array();
      Africa_Cities_List[0] = new CityObj("Abidjan", 0, No_DST, "ABI");
      Africa_Cities_List[1] = new CityObj("Accra", 0, No_DST, "ACC");
      Africa_Cities_List[2] = new CityObj("Addis Ababa", 3, No_DST, "ADA");
      Africa_Cities_List[3] = new CityObj("Algiers", 1, UK_Europe_DST, "ALJ");
      Africa_Cities_List[4] = new CityObj("Antananarivo", 3, No_DST, "ANT");
      Africa_Cities_List[5] = new CityObj("Bamako", 0, No_DST, "BAM");
      Africa_Cities_List[6] = new CityObj("Benin City", 1, No_DST, "BEN");
      Africa_Cities_List[7] = new CityObj("Bloemfontein", 2, No_DST, "BLO");
      Africa_Cities_List[8] = new CityObj("Cairo", 2, UK_Europe_DST, "CAI");
      Africa_Cities_List[9] = new CityObj("Cape Town", 2, No_DST, "CTC");
      Africa_Cities_List[10] = new CityObj("Dakar", 0, No_DST, "DAK");
      Africa_Cities_List[11] = new CityObj("Dar-Es-Salaam", 3, No_DST, "DAR");
      Africa_Cities_List[12] = new CityObj("Durban", 2, No_DST, "DUR");
      Africa_Cities_List[13] = new CityObj("Freetown", 0, No_DST, "FRE");
      Africa_Cities_List[14] = new CityObj("Harare", 2, No_DST, "HAR");
      Africa_Cities_List[15] = new CityObj("Johannesburg", 2, No_DST, "JOH");
      Africa_Cities_List[16] = new CityObj("Kampala", 3, No_DST, "KAM");
      Africa_Cities_List[17] = new CityObj("Khartoum", 2, No_DST, "KAR");
      Africa_Cities_List[18] = new CityObj("Kinshasa", 1, No_DST, "KIN");
      Africa_Cities_List[19] = new CityObj("Luanda", 2, No_DST, "LUA");
      Africa_Cities_List[20] = new CityObj("Maputo", 2, No_DST, "MAP");
      Africa_Cities_List[21] = new CityObj("Mbala", 2, No_DST, "MBA");
      Africa_Cities_List[22] = new CityObj("Monrovia", 0, No_DST, "MON");
      Africa_Cities_List[23] = new CityObj("Ndjamena", 1, No_DST, "NDJ");
      Africa_Cities_List[24] = new CityObj("Pointe Noire", 1, No_DST, "PNO");
      Africa_Cities_List[25] = new CityObj("Port Elizabeth", 2, No_DST, "POE");
      Africa_Cities_List[26] = new CityObj("Pretoria", 2, No_DST, "PRE");
      Africa_Cities_List[27] = new CityObj("Rabat", 0, No_DST, "RBT");
      Africa_Cities_List[28] = new CityObj("Tripoli", 1, No_DST, "TRI");
      Africa_Cities_List[29] = new CityObj("Tsumeb", 2, No_DST, "TSU");
    timeFunctions.js
    Code:
    function CityObj(cityName, cityOffset, cityDST, cityAcronym) {
     this.cityName = cityName;
     this.cityOffset = cityOffset;
     this.cityDST = cityDST;
     this.cityAcronym = cityAcronym;
    }
    function writeItAll(theCityArray,continente) {
       var array_city = [];//new Array(theCityArray.length+1);
       array_city.push(new Option("&lt; Scegli citt&aacute; &gt;","&lt; Scegli citt&aacute; &gt;"));
       for(var j=0; j < theCityArray.length; j++)
       {array_city.push(new Option(theCityArray[j].cityName,theCityArray[j].cityAcronym));}
       for(var i=0; i < array_city.length; i++)
       {document.forms[0].elements[continente].options[i] = array_city[i];}
     }

  3. #3
    Join Date
    Nov 2009
    Posts
    109
    Wawwww! Thanks very much for your help!

  4. #4
    Join Date
    Jul 2005
    Location
    Tangerang, Indonesia
    Posts
    171
    Ok... no problem, you're welcome

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles