Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 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 Attached Files
    Last edited by linguist2000; 08-21-2011 at 09:58 AM. Reason: add files

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What it is you're trying to do, and what is this not doing for you - exactly?

  • #4
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it doesnt fill cities when the page starts

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 1 Time in 1 Post
    please exactly state what is your problem so that we may help you better, on first look the coding seems right to me

  • #7
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote 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


  •  

    Posting Permissions

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