Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although @zerkms gave a pointer to the correct information, that might not be enough. I've created a <a href="http://jsfiddle.net/lightningwhelk/RDGGY/">fiddle with a working example</a>: to help. The basic parts are:</p> <ol> <li>A javaScript function that uses the maps API to put down a marker where the user clicks (this is placeMarker)</li> <li>A javaScript click handler for the submit button that prevents the normal form submit and records the current latlng of the marker in a hidden form field</li> <li>An invocation of the normal form submit</li> </ol> <p>Here is the placeMarker code:</p> <pre><code>function placeMarker(location) { if (marker) { marker.setPosition(location); } else { marker = new google.maps.Marker({ position: location, map: mapInstance }); } } </code></pre> <p>And here is the jQuery code used for handling the submit:</p> <pre><code>$("#submitbutton").on("click", function(e) { // Prevent normal submit action e.preventDefault(); // Collect current latlng of marker and put in hidden form field if (marker) { $("#latlngfield").val(marker.getPosition().toString()); } else { $("#latlngfield").val("not entered"); } // Show results for debugging submitAction(); // Uncomment this for production and remove submitAction() call // $("#dataform").submit(); }); </code></pre> <p>Here's the form I used:</p> <pre><code>&lt;form id="dataform"&gt; &lt;fieldset&gt; &lt;legend&gt;Form Information&lt;/legend&gt; &lt;label for="firstnamefield"&gt;First Name&lt;/label&gt; &lt;input type="text" name="firstname" id="firstnamefield"&gt;&lt;br&gt; &lt;label for="lastnamefield"&gt;Last Name&lt;/label&gt; &lt;input type="text" name="lastname" id="lastnamefield"&gt;&lt;br&gt; &lt;input type="reset" name="reset" value="Clear"&gt; &lt;input type="submit" name="submit" id="submitbutton" value="Submit Data"&gt; &lt;input type="hidden" name="latlng" id="latlngfield"&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>The submitAction is not needed in production, I just wanted to show what happens with the values:</p> <pre><code>function submitAction() { alert("Value of firstname is " + $("#firstnamefield").val()); alert("Value of lastname is " + $("#lastnamefield").val()); alert("Value of latlng is " + $("#latlngfield").val()); } </code></pre> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload