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.
-
1Thanks, wish I'd been told that sooner. Although sometimes one doesn't always get an adequate answer, I usually turn out fine.Austin Burk– Austin Burk2012年01月15日 15:40:13 +00:00Commented Jan 15, 2012 at 15:40
-
See stackoverflow.com/questions/4484517/submit-form-via-javascripterikxiv– erikxiv2012年01月15日 16:03:37 +00:00Commented Jan 15, 2012 at 16:03
-
It's not solved..I don't have my answer.Austin Burk– Austin Burk2012年01月15日 21:03:06 +00:00Commented Jan 15, 2012 at 21:03
2 Answers 2
You have to get the form object and call the submit(); function provided by HTMLFormObject.
document.getElementById('myForm').submit();
Comments
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>