Jump to content

Update database record from Javascript


Adam Moore

Recommended Posts

Posted

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.

 

Posted

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.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...