Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9238955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:52:42+00:00 2026-06-18T07:52:42+00:00

I’m writing a web application in Python. I’ve got a form that takes as

  • 0

I’m writing a web application in Python. I’ve got a form that takes as input two user-specified entries, one is a text field and the other is a selection. Upon submission, I GET these entries and store them to the database, which later gets queried and posted up. Anyway, it takes JavaScript to grab the User’s coordinates, which I need, and I’ve got the JavaScript embedded in my template and it’s SUPPOSED to be inputting the coordinates to “hidden” input fields. I can’t seem to call and successfully retrieve those element’s contents with the standard call (using GAE and Python)

latitude = self.request.get("latitude")
longitude = self.request.get("longitude")

Here is the embedded JavaScript and form input elements:

   <script>
   function get_location()      {
                            if (navigator.geolocation)      {
                            navigator.geolocation.getCurrentPositon(showPosition);
                            } else {
                                    alert('It appears geolocation isnt enabled.');
                            }
                    }
                    function showPosition(position)
                            {
                            $("#latitude").val(position.coords.latitude);
                            $("#longitude").val(position.coords.longitude);
                    }
    </script>

    <input type="hidden" name="latitude" id="latitude" />
    <input type="hidden" name="longitude" id="longitude" />
    <br>
    <input type="submit" onclick="get_location()" value="Update">

FYI, this is all within the same form. So, theoretically, this should be generating the latitude and longitude of the user and then passing those values to their respective input fields. Is there any obvious reason this isn’t working? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:52:44+00:00Added an answer on June 18, 2026 at 7:52 am

    getCurrentPosition() is asynchronous. It probably will not have completed before your form is submitted, thus the field values are not filled in.

    One way to solve that problem is to not submit your form until getCurrentPosition() has finished and has called showPosition(). To do that, you would need to block the default form submission by returning false from get_location() and returning that return value in your onclick handler and then programmatically submit the form when showPosition() is called after the hidden location fields have been set.

    Another way to solve that issue is to fill in the current position when the form is initially displayed and not wait until you’re trying to submit it.

    FYI, see Uncaught ReferenceError: lat is not defined for someone else having a similar problem today with the asynchronous nature of getCurrentPosition().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm interested in microtypography issues on the web. I want a tool to fix:
I am doing a simple coin flipping experiment for class that involves flipping a
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.