1

I am doing my javascript assignment in which I have a form and there are multiple buttons in it. I want that javascript should render like

<form>
<input />
<button />
</form>

but it is rendering like this

 <form> </form>
    <input />
    <button />

sample code

var formTag = document.createElement('form');
document.body.appendChild(formTag);
var txtInput = document.createElement("input");
var txtNode = document.createTextNode("0");
txtInput.setAttribute("id", "txtInput");
txtInput.appendChild(txtNode);
document.form.appendChild(txtInput);
2
  • becoz jquery and javascript community is interlinked. Commented Oct 26, 2012 at 19:20
  • Billz, @j08691 is implying the post should be tagged based on its content and semantics, not ratings considerations. Commented Oct 26, 2012 at 19:26

2 Answers 2

3

You're mistakenly appending the input element to the document's form element (which, by the way, does not exist - you probably meant document.forms[0]).

Append the input to the formTag object instead, like so:

formTag.appendChild(txtInput);
Sign up to request clarification or add additional context in comments.

Comments

1

Try appending the txtInput to your formTag object instead..

var formTag = document.createElement('form');
document.body.appendChild(formTag);
var txtInput = document.createElement("input");
var txtNode = document.createTextNode("0");
txtInput.setAttribute("id", "txtInput");
txtInput.appendChild(txtNode);
formTag.appendChild(txtInput);

Comments

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.