Hi, its me again. I've seen the other code for looping textbox but it goesn't seem to apply in our script. What we need is a specific text box that loops when the user inputs a certain number of textboxes that he want to put.
Example: there's a text box in which the user will enter the number of textboxes that he wanted to display, say 3. So after I click the submit button, there should be 3 textboxes as the output.

Hi, its me again. I've seen the other code for looping textbox but it goesn't seem to apply in our script. What we need is a specific text box that loops when the user inputs a certain number of textboxes that he want to put.
Example: there's a text box in which the user will enter the number of textboxes that he wanted to display, say 3. So after I click the submit button, there should be 3 textboxes as the output.

<table>
<? 
for($i=0;$i<10;$i++)
{?>
<tr>
<td>

<input type="text" name="textbox<?=$i ?>" id="textbox" /></td>
</tr>
<?
}
?>
</table>

in above for loop you can send dynamically values

In this script, it will automatically output 10 text boxes. The concept was here though it should produce an output of text boxes depending on the number of text boxes that the user entered.

<table>
	  
      <?php

	  for($i=0;$i<10;$i++)
      {?>
      <tr>
      <td>
       
      <input type="text" name="textbox<?=$i ?>" id="textbox" /></td>
	  
      </tr>
      <?php
      }
      ?>
	  
      </table>
	  <input type="submit" value="Submit">

The script should ask the user as to how many text boxes does the user wants so if i entered 5 then click submit, it should produce 5 text boxes.

Member Avatar for diafol
<?php
if(!isset($_POST['send_hm'] || (isset($_POST['how_many']) && is_int($_POST['how_many'])== false)){
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<label for="how_many">How many boxes?</label>
<input type="text" id="how_many" name="how_many" />
<input type="submit" id="send_hm" name="send_hm" value="Get Boxes!" />
</form>
<?php
}else{
$num = $_POST['how_many'];
?>
<form method="post" action="{some other page}" ...>
<p>Whatever your text</p>
<?php
  for($i = 1; $i <= $num; $i++){
    echo "\n\t<input type=\"text\" name="mytext[]" id="mytext_$i" />";
  }  
?>
 <input type="submit" name="send_boxes" id="send_boxes" value="Send" />
</form>
<?php
}
?>

I must admit the above code is horrible and hasn't been tested, but should work - or it's pretty close. However, you may get a better effect from some javascript. This can create inputs on the fly with 'add another textbox' button via "append".

BTW: mytext[] for box names so that the $_POST is an array and therefore easier to handle.

Use the below Specified Code for Looping Textbox:

<form name=textbox method=post>
How Many Textboxes you Want to Apper: <input type="text" name="how_many" /><br/>
<input type=submit value="Get Text Box" name=submit />
</form>
<?PHP
if (isset($_POST['submit']))
{
$how_many = $_POST['how_many'];
echo "<form name=something_here method=post>";
for ($i=0; $i<$how_many; $i++)
{
	echo "Textbox $i: <input type=text name=text id=text_$i><br/>";
}
echo "<input type=submit name=submit value=Submit></form>";
}
?>
Member Avatar for diafol

Sorry to pick holes hem, but your html is poorly formed - no quotes around your attribute values.

Thanks guys! Its now working fine.

sorry ardev but the code posted by me is only php coding. i am not more consideration on html formatting.
anyway thanx for your suggestion i will be remember ths always.

how can database get value from Looping Textbox?....i'm new here

Member Avatar for diafol

You use name attributes with array values:

name="text[]"

You then pick them up with $_POST['text'] as an array.

Hi its me,
I have use that code shown above in my form wizard form but they do not work

commented: Try to message those above or start a new discussion. +15

Try to message those above or start a new discussion.

If you’re not a moderator, you need to be a DaniWeb Premium member in order to send a message.

commented: Nice perk of being a member (or mod or staff!) That said, those in the thread should get an alert soon. +15

Lots of perks :)

https://www.daniweb.com/donate/index

The ability to message anyone is the only DaniWeb Premium perk that mods get for free because they need it to do their job effectively. (Eg message someone saying they edited their post, etc.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.