Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add textboxes dynamically in Javascript?

By default I have 5 textboxes. When a user clicks on a button, one textbox should be added.

How could I do this?

like image 495
noob Avatar asked Sep 07 '09 17:09

noob


People also ask

How do you insert a textbox in JavaScript?

You can create a textbox using JavaScript in two simple steps: First, you need to use the createElement("input") method of the document object to create an <input> element. Then, you need to set the type attribute of the <input> element that you've created to "text" using the Element. setAttribute() method.

What is a dynamic text box?

Intro. Like a standard textbox, a dynamic textbox is used to build Cards containing text. The difference is that with a standard textbox, the text in the box comes directly from the DataSet, and only one macro is available; this macro lets you dynamically reference the first value in your selected value column.


1 Answers

If you replace the innerHTML, the previously entered values will be cleared, to avoid that, you can append the input elements programmatically:

var input = document.createElement('input'); 
input.type = "text"; 
//...    
container.appendChild(input); 

Check this example.

like image 193
Christian C. Salvadó Avatar answered Oct 13 '22 19:10

Christian C. Salvadó