Web Analytics Made Easy -
StatCounter Can anyone help please - CodingForum

Announcement

Collapse
No announcement yet.

Can anyone help please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can anyone help please

    html code is like this
    Code:
    <html>
    <head>
    <script language="jscript" src="cities.js" type="text/jscript"></script>
    <script language="javascript" type="text/javascript">
        function onLoad() {
        try {FillCitiesAndCounties("_cityID", "_countyID", 0, 0);} catch(ex) {}
        }
        window.attachEvent("onload", onLoad);
    </script>
    </head>
    
    <body>
    <form>
    <tr>
    <td><label>City</label></td>
    <td><select id="_cityID" name="cityid" style="width:100%;"><option value="0">(All)</option></select></td>
    <td><label>County</label></td>
    <td><select id="_countyID" name="countyid" style="width:100%;"></select></td>
    </tr>
    </form>
    </body>

    And the cities.js is like this:
    Code:
    var cities = new Array("", "America", "England", "Germany");
    var counties = new Array();
    counties[0] = new Array("");
    counties[1] = new Array("", "New York", "Washington");
    counties[2] = new Array("London", "WEstminister");
    counties[3] = new Array("Berlin", "Kohln");
    
    
    function SortByName(arr, start) {
    	var result = new Array();
    	for(var i = start; i < arr.length; i++)
    		result.push({Id: i, Name: arr[i]});
    	result = result.sort(function() {
    		return arguments[0].Name.localeCompare(arguments[1].Name);
    	});
    	return result;
    }
    
    
    function FillCitiesAndCounties() {
    	var sel1 = document.getElementById(arguments[0]), sel2 = document.getElementById(arguments[1]);
    	var cityId = (arguments[2] != null) ? arguments[2] : 1, countyId = arguments[3] ? arguments[3] : 0;
    	var arr = SortByName(cities, 1);
    	for(var i = 0; i < arr.length; i++)
    		sel1.addOption(arr[i].Id, arr[i].Name, arr[i].Id == cityId);
    	sel2.addOption(0, "", countyId == 0);
    	arr = SortByName(counties[cityId], counties[cityId][0] == "" ? 1 : 0);
    	for(var i = 0; i < arr.length; i++)
    		sel2.addOption((cityId * 100) + arr[i].Id, arr[i].Name, countyId == (cityId * 100) + arr[i].Id);
    	sel1.attachEvent("onchange", function() {
    		while(sel2.options.length > 0)
    			sel2.options.remove(0);
    		sel2.addOption(0, "", true);
    		var cityId = parseInt(event.srcElement.options[event.srcElement.selectedIndex].value);
    		var arr = SortByName(counties[cityId], counties[cityId][0] == "" ? 1 : 0);
    		for(var i = 0; i < arr.length; i++)
    			sel2.addOption((cityId * 100) + arr[i].Id, arr[i].Name, false);
    
    	});
    }
    Nothing seems wrong but it doesnt work
    Attached Files
    Last edited by linguist2000; Aug 21, 2011, 04:58 AM. Reason: add files

  • #2
    Don't expect people to help with such poor information. If at least your code would be commented... Nothing seems wrong? Are you sure?
    Chuck Norris counted to infinity.
    Twice.

    Comment


    • #3
      What it is you're trying to do, and what is this not doing for you - exactly?

      Comment


      • #4
        it doesnt fill cities when the page starts

        Comment


        • #5
          Have you tried using Firebug?

          Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.

          All the code given in this post has been tested and is intended to address the question asked.
          Unless stated otherwise it is not just a demonstration.

          Comment


          • #6
            please exactly state what is your problem so that we may help you better, on first look the coding seems right to me

            Comment


            • #7
              Originally posted by whitecouncil View Post
              please exactly state what is your problem so that we may help you better, on first look the coding seems right to me
              the problem is: it doesnt fill cities from array when the page starts

              Comment

              Working...
              X
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎