I used code from http://viralpatel.net/blogs/dynamic-add-textbox-input-button-radio-element-html-javascript/ html-javascript/ .my code is this:
<HTML>
<HEAD>
<TITLE>Dynamically add Textbox, Radio, Button in html Form using JavaScript</TITLE>
<SCRIPT language="javascript">
function add() {
for (i=1; i<=5; i++)
{
???? //Create an input type dynamically.
???? var element = document.createElement("input");
?
???? //Assign different attributes to the element.
???? element.setAttribute("type", i);
???? element.setAttribute("name", i);
???? element.setAttribute("value", i);
?
?
??? ?var foo = document.getElementById("fooBar");
?
???? //Append the element in page (in span).
???? foo.appendChild(element);
}
?
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<H2>Dynamically add element in form.</H2>
Select the element and hit Add to add it in form.
<BR/>
<INPUT type="button" value="Add" onclick="add()"/>
?
<span id="fooBar"> </span>
?
</FORM>
</BODY>
</HTML>
That code works. But instead of adding it horizontally, I want every new text field added in a new line. I've tried to use </script><br/><script>
, <html><br/></html>
, document.write("
")
, and document.write("
")
in the loop function but it doesnt work like what I want. What should I do?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…