1

I have the following HTML/Javascript code: http://jsfiddle.net/xxwa7/ and I am trying to submit the variable GPSlocation back to the server.

I am using Google App Engine with Python and Jinja2. I would like to submit it with a POST method but I am not sure how to do that with a javascript method. I would imagine this is somewhat simple but I can't find it online anywhere.

Thanks!

2
  • 3
    What you are looking for is called AJAX. Very easy with jQuery etc. (you don't want to do it manually, it's just annoying) Commented Sep 9, 2012 at 2:45
  • its not too bad manually but yeah jquery simplifies it alot Commented Sep 9, 2012 at 2:51

1 Answer 1

3

In the end wash, there are only three ways to pass data from a web browser to a server.

  1. File upload: Doesn't count in this case. Can be ignored.
  2. Submit a form: Pass data as form fields, process on remote site as a form. Data can be passed back to Javascript either as form fields or embedding var statements in the new document.
  3. AJAX: Submit a small amount of data, wait for the server to give you a small amount of data back. Not difficult to do, but requires a slightly different way of thinking. JSON is frequently used as a standard of moving data around. There are various AJAX wrappers out there, most as easy to use as the over-advertised jQuery.

To post a form with Javascript is fairly easy. Create the form using your standard HTML markup. Use standard Javascript and DOM methods to update the form values.

Assuming only one form on your document:

document.forms[0].submit();

Edit: From the comments:

For the HTML:

<form action="#">
  <div>
    <input type="hidden" name="datatosendback" id="datatosendback">
  </div>
</form>

For the Javascript:

document.getElementById("datatosendback").value = "OH! Mr KOTER! SEND ME!";

There are a number of other ways to access form fields and values. A google search for 'javascript modify forms` brings up pages.

Sign up to request clarification or add additional context in comments.

2 Comments

I know how to submit a form with Javascript. What I want to do is submit a Javascript variable. I don't know how to put the variable into the HTML
Updated my comment to give one example

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.