directedition
directedition

Reputation: 11705

Getting a form to POST in Javascript

I'm populating a form in Javascript before sending it off, and thus need to post the form with javascript:

var url = "http://urltomyaction";
var myvar = "somedata";
var = oFormObject = document.forms['fileselectform'];
oFormObject.elements['myvar'].value = myvar;
oFormObject.action = url;
oFormObject.submit();

My issue is that I need to put the parameters in a POST, instead of encoding them in the URL, but this method results in a GET with the form parameters in the URL. What am I missing? How can I specify to POST?

Upvotes: 0

Views: 320

Answers (1)

ruakh
ruakh

Reputation: 183201

You set its method attribute to 'POST', either in HTML:

<form ... method="POST" ...>...</form>

or in JavaScript:

oFormObject.method = 'POST';

Upvotes: 3

Related Questions