0

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>

1 Answer 1

1

There is no "crate" element in html:

crate = document.createElement("crate");

should be

crate = document.createElement("input");

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! Worked like a charm. I didn't understand the relationship between what was in quotations and what was before the equals sign. Appreciate it!
well thats why I'm here isn't it?
If you do not know about the "relationship between what was in quotations and what was before the equals sign" my answer will probably not help you in terms of understanding. StackOverflow is not here to teach you the bare basics. That's what the countless tutorials on the internet are there for. Also valid answers should be marked as such.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.