...

View Full Version : Can anyone help please



linguist2000
08-21-2011, 10:54 AM
html code is like this


<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:


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

Arnaud
08-21-2011, 03:19 PM
Don't expect people to help with such poor information. If at least your code would be commented... Nothing seems wrong? Are you sure?

dgonz
08-21-2011, 08:02 PM
What it is you're trying to do, and what is this not doing for you - exactly?

linguist2000
08-21-2011, 10:29 PM
it doesnt fill cities when the page starts

Philip M
08-22-2011, 08:50 AM
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.

whitecouncil
08-22-2011, 08:53 AM
please exactly state what is your problem so that we may help you better, on first look the coding seems right to me

linguist2000
08-22-2011, 11:40 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum