Rajesh Kumar
Rajesh Kumar

Reputation: 13

How to generate textboxes dynamically based on input number?

I am doing online shoping webpage.i required to show textboxes based on input number By using onKeyPress Event.

Ex: textBooks Howmany

 PHP Guid     3

Then create 3 textboxes with same name PHP Guid in bellow.

like

 PHP Guid 
 PHP Guid
 PHP Guid 

Thanking you in Advance.

Upvotes: 0

Views: 4091

Answers (3)

Rahul Chordiya
Rahul Chordiya

Reputation: 542

Hima

function duplicate() { var l=Number(document.getElementById('textbox name where u r entered')); for($i = 0; $i<l; $i++) { <input type=\’Text\' name=\'group'.$i.'\' id=\'Textbox'.$i.'\' value=\'' pass text box text here '\' >''</input>'; } }

this is javascript.

and babonk give you solution in php.

Upvotes: 0

user319198
user319198

Reputation:

<html>
<head>
<title>Dynamic Form</title>
<script language="javascript">
function changeIt(count)
{
var i;
for(i=0;i<count;i++)
{
my_div.innerHTML = my_div.innerHTML +"<br><input type='text' name='mytext'+ i>";
}

}
</script>
</head>
<body>

<form name="form" action="post" method="">
<input type="text" name="t1" onblur="changeIt(this.value)">

<div id="my_div"></div>
</form>
</body>

Upvotes: 2

Bhanu Prakash Pandey
Bhanu Prakash Pandey

Reputation: 3785

try this

if input number is 5

for($j = 1; $j <= 5; $j++) {

echo "<input type="text"  name="textfield[]">";

}

Upvotes: 1

Related Questions