Share on Google+Share on Google+

Javascript generate textbox

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>

Advertisements

Posted on: December 20, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.