1

I'd like to be able to submit a form automatically on an event ( a generic form, for user tracking).

For example, create a POST to http://www.example.com/index.php?option=track&variable=variable application/x-www-form-urlencoded with stuff like

username=usernamestring
otherdata=otherdata_string
otherdata2=otherdata string 2

The actual string will be preformatted, though, because all it is is like a 'ping'. It needs to be submitted onevent, with external js ( http://example.com/scripts/js.js )

What the hay should I do? This is getting annoying.

Update: I guess I didn't really make myself clear; I have a premade form that isn't supposed to display on the page; it needs to submit on an event. The form fields do not exist on the page; all I do is link to the script on the page and it executes onLoad.

POST uri: http://www.example.com/index.php?option=track&variable=variable The arguments above (option=track and variable=variable) are not the form details (postdata).

The content type is application/x-www-form-urlencoded , and has the following keys/values.

username=usernamestring
otherdata=otherdata_string
otherdata2=otherdata string 2 (when encoded, the spaces get turned to %20's.)

I need a script that submits this when run.

3
  • 1
    Thanks, wish I'd been told that sooner. Although sometimes one doesn't always get an adequate answer, I usually turn out fine. Commented Jan 15, 2012 at 15:40
  • See stackoverflow.com/questions/4484517/submit-form-via-javascript Commented Jan 15, 2012 at 16:03
  • It's not solved..I don't have my answer. Commented Jan 15, 2012 at 21:03

2 Answers 2

4

You have to get the form object and call the submit(); function provided by HTMLFormObject.

document.getElementById('myForm').submit();
Sign up to request clarification or add additional context in comments.

Comments

1

1) with the following, (while page is loaded), the form will be immediately autosubmited

<form action="post.php" name="FNAME" method="post">
<input type="text" name="example22" value="YOURVALUE" />
<input type="submit" />
</form>
<SCRIPT TYPE="text/JavaScript">document.forms["FNAME"].submit();</SCRIPT>

another formSubmit alternative - submits any script:

document.forms[0].submit();

2) or use button click after 2second:

<SCRIPT TYPE="text/JavaScript">setInterval(function () {document.getElementById("myButtonId").click();}, 2000);</SCRIPT>

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.