Jump to content
You're invited! Join our 4.6 Live Event on ZOOM 6/24 ×

Community

Update database record from Javascript


Adam Moore
 Share

Recommended Posts

Is it possible to update a database record from javascript? I'm trying to save the longitude and latitude values from a google maps geocode function but I can't for the life of me figure how to update a database record from javascript.

 

I have the following code that returns the latitude and longitude from an array in javascript.

            var latitude = results[0].geometry.location.lat()
            var longitude = results[0].geometry.location.lng()
 

I need to save the javascript variables "latitude" and "longitude"  to my database with fields named "lat" and "long". I've been trying to figure this out for a few days now and haven't had any luck. Any help would be greatly appreciated.

 

Link to comment
Share on other sites

Are these values available in the record form, or record view? 

If this is in the form, it's just a matter of populating the form fields with the values, but you need to know the field ID first.

$( 'form input[name="content_field_X"]' ).val( latitide );

If it's somewhere else you need to do an AJAX request to a back-end method that does the saving. AFAIK this is not built in, and would require a plugin.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We use technologies, such as cookies, to customise content and advertising, to provide social media features and to analyse traffic to the site. We also share information about your use of our site with our trusted social media, advertising and analytics partners. See more about cookies and our Privacy Policy