php - javascript code execute on button click but not on enter key presses -


i searching location onclick on button. result getting on onclick button. same code have put in submit function here searching not working.

on button click code.(this working)

    $("#gobuttton").click(function() {         $("#gmaplatlon").validate({             rules:{"latitude":{number:true}, "longitude":{number:true}, "zoom":{digits:true,min:0}},             errorplacement:errormessages         });         $("#address").change(function(){             geocoder.geocode({"address": $(this).attr("value")}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setzoom(16); map.setcenter(results[0].geometry.location); } else { alert("geocode not successful following reason: " + status); } });         }); }); 



press enter button code(same not working)

     $('#frm').keypress(function(e) {      var code = e.keycode;      if(code === 13){          e.preventdefault();          alert(code);          $("#gmaplatlon").validate({rules:{"latitude":{number:true}, "longitude":{number:true}, "zoom":{digits:true,min:0}}, errorplacement:errormessages});          $("#address").change(function(){ geocoder.geocode({"address": $(this).attr("value")}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setzoom(16); map.setcenter(results[0].geometry.location); } else { alert("geocode not successful following reason: " + status); } }); });        } }); 


my functionality - enter address in textbox , press enter key should searching on google map, executed on button click not when enter key pressed.

html code follows

<form method="post" name="frm" id="frm" enctype="multipart/form-data" action="<?php echo site_url('home/sendmapdata');?>">   <input name="address" type="text" id="address" border: solid 1px; " size="60" value="search address" onclick="this.value=''">  <input type="button" id="gobuttton" value="go">  <div id="map_canvas" style="height: 480px; width:665px; " ></div>  <input type="hidden" name="gmaplatlon" value="true">  <p align="center"> <input type="submit" name="okbutton" value="ok" > </p> </form> 

tyr this:

$(document).ready(function(){     $('#address').keypress(function(e) {          var code = e.keycode;          if(code === 13){              //e.preventdefault();              alert(code);              $("#gmaplatlon").validate({rules:{"latitude":{number:true}, "longitude":{number:true}, "zoom":{digits:true,min:0}}, errorplacement:errormessages});              $("#address").change(function(){ geocoder.geocode({"address": $(this).attr("value")}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setzoom(16); map.setcenter(results[0].geometry.location); } else { alert("geocode not successful following reason: " + status); } }); });          }          return false;     }); }); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -