Adam Moore Posted September 8, 2019 Posted September 8, 2019 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.
Martin A. Posted September 8, 2019 Posted September 8, 2019 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.
Aiwa Posted September 8, 2019 Posted September 8, 2019 Database manipulation from the UI directly, not going through a back end, is poor practice. It will only cause you further grief down the road.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.