1

I am using Goole Maps and want to include 2 javascript variables with a form post (longitude and latitute of the marker). Here's what I have:

 function saveData() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var type = document.getElementById("type").value;
      var latlng = marker.getLatLng();
      var lat = latlng.lat();
      var lng = latlng.lng();

I need to include "var lat" and "var lng" with an existing form post.

<form id="form1" name="form1" method="post" action="catchprocess.php">

Thanks for any help you con provide!

2 Answers 2

4

you can assign these lattitude and longitude inside hidden field in a form

  var lat = latlng.lat();
      var lng = latlng.lng();
    document.getElementById("t1").value=lat;
    document.getElementById("t2").value=lng;

   <form id="form1" name="form1" method="post" action="catchprocess.php">
        <input type="hidden" name="lat" id="t1">
        <input type="hidden" name="long" id="t2">
//form end

In catchprocess.php,you can access thes lat,long through

$_POST['lat'] and $_POST['long'] 
Sign up to request clarification or add additional context in comments.

Comments

1
var inp = document.createElement('input');
inp.setAttribute('type', 'text'); // or hidden
inp.setAttribute('name', 'lat');
inp.setAttribute('value', lat);

document.getElementById("form1").appendChild(inp)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.