Home Tutorial Javascript Javascript generate textbox

 
 

Share on Google+Share on Google+
Javascript generate textbox
Posted on: December 20, 2012 at 12:00 AM
Advertisement
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>
Advertisement

Related Tags for Javascript generate textbox:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 20, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com