-1

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.

5
Contributors
9
Replies
16
Views
7 Years
Discussion Span
Last Post by diafol
-1

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

Edited by muralikalpana: n/a

0

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.

0
<?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.

Edited by diafol: n/a

0

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>";
}
?>
0

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

0

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.

0

You use name attributes with array values:

name="text[]"

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.