function add() {
//Create an input type dynamically.
var element = document.createElement("input");
//Create Labels
var label = document.createElement("Label");
label.innerHTML = "New Label";
//Assign different attributes to the element.
element.setAttribute("type", "text");
element.setAttribute("value", "");
element.setAttribute("name", "Test Name");
element.setAttribute("style", "width:200px");
label.setAttribute("style", "font-weight:normal");
// 'foobar' is the div id, where new fields are to be added
var foo = document.getElementById("fooBar");
//Append the element in page (in span).
foo.appendChild(label);
foo.appendChild(element);
}
Best would be to attach an event on to the onclick of the button, that will set a div's visibility to inline. This is about the best way I can see for this, considering flexibility and robustness.
If you replace the innerHTML, the previously entered values will be cleared, to avoid that, you can append the input elements programmatically:
Check this example.
Javascript Function
Html part,
And, Its done!
Best would be to attach an event on to the
onclick
of the button, that will set a div's visibility toinline
. This is about the best way I can see for this, considering flexibility and robustness.Have a look here for example code.
try this