Sunday 15 May 2011

javascript - Check value of fields before running function in jquery -


I basically want a script on the page which shows a map when it gets two fields on the page "lng" And the value of "latitude" is.

This means that if the values ​​contain fields on the page, it will try and display the map, but if not, it will not be.

This is the code so far:

  Display the map of the function () {var latval = $ ('input [id = lat]'). Val (); Var lngval = $ ('input [id = lng]'). Val (); Var map option = {zoom: 8, center: new google.maps.LatLng (latevel, langela), map type eid: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true, scroll-wheel: wrong, dragable: incorrect }; Var map = new google.maps.Map (document.getElementById ('map_canvas'), map options); } $ (Function () {mapDisplay ();});   

I am not very good at jquery at the moment, but this is what I tried, which does not work:

  if (latval! = NULL & What is this method is? Does it?   

try it

  if (! IsNaN (latval) & amp; ; Amp; isNaN (Lngval)) {bases it basically checks if there are 2 input numbers, and only if the condition in true condition will increase.  

In addition to

  var latval = $ ('input [id = lat]'). Val (); Var lngval = $ ('input [id = lng]'). Val ();   

can be safely written as

  var latval = $ ('# lat'). Val (), lngval = $ ('# lng') .val ();   

You can hook the change event to the input displaying the map

code

  function map display () {var latval = $ ('# lat'). Val (), lngval = $ ('# lng'). Val (); (! INN (Parasflat (lacel)) and! INNA (Parcephlat (langela)) {var map options = {zoom: 8, center: new google.maps.LatLng (Latvell, languel), map type EID: Google Maps . MapTypeId.ROADMAP, disableDefaultUI: true, scrollable: false, dragable: false}; Var map = new google.maps.Map (document.getElementById ('map_canvas'), map options); $ ('# Map_canvas') removeClass ('hidden'). } And {$ ('# map_canvas'). AddClass ('hidden'); }} $ (Function () {$ ('Input'). ('Change', Display map). Trigger ('change');});   



No comments:

Post a Comment