0

I have form elements here that work great:

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

That successfully launches the javascript code below. When I change the adreessinput1 from

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

I tried changing the $("#showaddress1").click(geoCode1); from click to change to no effect. what am I doing wrong?

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); 
});

tony

1 Answer 1

2

On <input id="addreessinput1" ... /> you use id, on <select name="addreessinput1" ... /> you use the name property.

$("#addreessinput1") will most likely not find the select and therefor return null as value.

7
  • I see what you mean, I tried to add <select id="addreessinput1" name="addreessinput1" style="width:20%"> with id but got the same result...do I need to change the var address = $("#addreessinput1").val(); to make this work? Feb 28, 2013 at 21:17
  • Yes, if you mean click to change here, right? $("#showaddress1").click(geoCode1); Feb 28, 2013 at 21:24
  • hmm... yeah, I just meant whether you added the id tag and changed .click( to .change( at the same time. thinking about other issues...
    – StrubT
    Feb 28, 2013 at 21:26
  • Yes, I've done both. I have no idea, I figured it would be an easy change. Feb 28, 2013 at 21:31
  • Yes, me too... can you alert the content of address?
    – StrubT
    Feb 28, 2013 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.