将表单元素从输入更改为Select break JavaScript函数

时间:2013-02-28 20:19:39

标签: javascript google-maps

我这里的表单元素很有用:

<input id="addreessinput1" style="width:20%" value="Enter Address"/>
<input id="showaddress1" type="button" value="Show Tech Home" style="width:10%"/>

成功启动下面的javascript代码。当我更改adreessinput1时

    <select name="addreessinput1" style="width:20%">
      <option value="my address">my address</option>
    </select>  

我尝试将点击中的$("#showaddress1").click(geoCode1);更改为无效。我做错了什么?

function geoCode1(){
    var address = $("#addreessinput1").val();
    geocoder = new google.maps.Geocoder();
    if(geocoder){
        geocoder.geocode( { 'address': address }, function(results, status) { // status is empty
        if (status == google.maps.GeocoderStatus.OK) {
            $("#lnf").css("display","none");
            var mposition = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());
            var image = new google.maps.MarkerImage('beachflag.png',
            new google.maps.Size(20, 32),
            new google.maps.Point(0,0),
            new google.maps.Point(0, 32));
            var shadow = new google.maps.MarkerImage('beachflag_shadow.png',
            new google.maps.Size(37, 32),
            new google.maps.Point(0,0),
            new google.maps.Point(0, 32));
            var shape = {
                coord: [1, 1, 1, 20, 18, 20, 18 , 1],
                type: 'poly'
            };
            if(mapa.addressmarker){
                mapa.addressmarker.setMap(null);
                mapa.bounds = new google.maps.LatLngBounds();
                mapa.map.fitBounds(mapa.bounds);
            }
            mapa.addressmarker = new google.maps.Marker({
                                position: mposition,
                                map:mapa.map,
                                title:address,
                                icon:image,
                                shadow:shadow,
                                shape:shape
                            });
            mapa.bounds.extend(mposition);
            mapa.map.fitBounds(mapa.bounds);
        }
        else if(status == google.maps.GeocoderStatus.ZERO_RESULTS){
            mapa.addressmarker.setMap(null);
            $("#lnf").css("display","block");
        }
    });
    }
}
$(document).ready(function(){
    $("#date1" ).datetimepicker({
        inline: true,
        dateFormat: "yy-mm-dd",
        timeFormat: "HH:mm",
        pickerTimeFormat: "HH:mm"
    });
    $("#date2" ).datetimepicker({
        inline: true,
        dateFormat: "yy-mm-dd",
        timeFormat: "HH:mm",
        pickerTimeFormat: "HH:mm",
        hour: 23,
        minute: 59
    });
    var mapOptions = {center: new google.maps.LatLng(26.549473, -81.847920),
        zoom: mapa.zoom,
        mapTypeId: google.maps.MapTypeId.HYBRID
    };
    mapa.map = new google.maps.Map(document.getElementById("map_canvas"),
    mapOptions);

    $("#user_id").change(getUserMarkers);
    $("#markerslist").change(upMarker);
    $("#getmarkers").click(getUserMarkers);
    $("#showaddress").click(geoCode);
    $("#showaddress1").click(geoCode1); 
});

              托尼             
            

1 个答案:

答案 0 :(得分:2)

<input id="addreessinput1" ... />上使用id,在<select name="addreessinput1" ... />上使用name属性。

$("#addreessinput1")很可能找不到select,因此返回null作为值。