Fusseldieb Fusseldieb - 1 month ago 8
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";
form.appendChild(input);

input2.name = "prod_order";
input2.value = "000456";
form.appendChild(input2);

document.body.appendChild(form);
form.submit();


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
document.createElement('input2')

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");