0
我有一个三个dropdownlists国家,城市和地区,初始空白选定值和一个HTML页面上的谷歌地图。我试图在用户从下拉列表中选择位置值时居中放大地图。Javascript/ASP.net在下拉列表更改后触发事件
因此,这里是我面临的一个问题的情形:
- 用户选择一个国家形成全国下拉列表。
- 我必须检索下拉列表更改后选定的值。
- 火更新谷歌地图
的事件中,我试图用平变化和更改JavaScript事件,但既造成从下拉列表检索的文本价值是文本的情况下,前值发送一个空文本(最初的空白文本)到谷歌地图。
那么,如何在下拉列表发生更改后触发事件?
这里是我的代码:
<asp:DropDownList ID="DropDownList_Country" runat="server" Height="29px" Width="209px"
Font-Size="18px" CausesValidation="false" onchange="MapLocationUpdater();">
function MapLocationUpdater() {
var address = getDropdownListAddress();
geocoder.geocode({ 'address': address },
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(11);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
}
);
}
function getDropdownListAddress() {
var ddlCountry = document.getElementById("<%=DropDownList_Country.ClientID%>");
var ddlCity = document.getElementById("<%=DropDownList_City.ClientID%>");
var ddlDistrict = document.getElementById("<%=DropDownList_District.ClientID%>");
var CountryTxt = ddlCountry.options[ddlCountry.selectedIndex].text;
var CityTxt = ddlCity.options[ddlCity.selectedIndex].text;
var DistrictTxt = ddlDistrict.options[ddlDistrict.selectedIndex].text;
return CountryTxt + " " + CityTxt + " " + DistrictTxt;
}
非常有趣的黑客。作品篦! – Eyad