Fusseldieb Fusseldieb - 11 months ago 87
Javascript Question

document.createElement Form only passes first value

I'm facing a strange problem. I'm trying to create a form with javscript, which submits data over POST, but only the first value is passed to the next page.

var form = document.createElement("form");
form.action = "print_order.php";
form.method = "post";

input = document.createElement("input");
input2 = document.createElement("input2");

input.type = "hidden";
input2.type = "hidden";

input.name = "product_id";
input.value = "000123";

input2.name = "prod_order";
input2.value = "000456";


In my implementation, the script executes, redirects me to the next page and then only the first value (product_id="000123") get a value over post, the next is blank. Why?

Answer Source

is the problem. That API accepts the name of a tag. "input2" is not a valid HTML tag. That line should read

input2 = document.createElement("input");