Javascript generate textbox


 

Javascript generate textbox

In this tutorial, you will learn how to generate a textbox on button click using javascript.

In this tutorial, you will learn how to generate a textbox on button click using javascript.

Javascript generate textbox

In this tutorial, you will learn how to generate a textbox on button click using javascript. Here is a javascript example that accepts the number from the user in order to generates the specific number of textboxes. On clicking the button with respect to each textbox, it will give you the value of that particular textbox.

Example

<html>
<script>
function generate()
{
var no = document.getElementById("text").value;
var tbl = document.getElementById("div");

for(var i =1;i<=no;i++)
{
tbl.innerHTML = tbl.innerHTML +' <input type="button" value="ok" onclick="getData('+i+');">'+'<input type="text" id=text'+i+'><br>\n';
}

}
function getData(i){
var value=document.getElementById('text'+i).value;
alert(value);

}
</script>
<body>
<pre>
<input type="button" value="OK" onclick="generate()"/><input type="text" id="text" />
</pre>
<div id="div">
</div>
</body>
</html>

Ads