Kyle Roarke
Kyle Roarke

Reputation: 27

Having an issue using the post method with javascript

Im playing with some basic javascript on a website and I'm having some issues. When I run this function it redirects to the page I want and only posts the size parameter. How do I post the cost parameter as well? The syntax is really confusing me. O.o

<script>
function selectcratesize(size, cost) {
 var form = document.createElement("form");
 input = document.createElement("input");
 crate = document.createElement("crate");

 form.action = "https://www.example.com";
 form.method = "post"

 input.name = "username";
 input.value = size;
 crate.name = "cost";
 crate.value  = cost;

 form.appendChild(input);
 form.appendChild(crate);

 document.body.appendChild(form);
 form.submit();
 }
</script>

Upvotes: 0

Views: 26

Answers (1)

LJᛃ
LJᛃ

Reputation: 8123

There is no "crate" element in html:

crate = document.createElement("crate");

should be

crate = document.createElement("input");

Upvotes: 1

Related Questions