please help... I have a looping textbox.. i cant get the value of the textbox when a user input a value.

when a user click the submit button, i want to post in to another page and display it..

I have a code here

for($i=1; $i<=$_REQUEST['no_textbox']; $i++)
   
      {
           
  	echo "	<table width=600>
	
	<tr align=center >
	<td colspan=2 bgcolor=#CCCCCC width=150><b>Passenger's Name No. ($i)</b></td>
	<td colspan3 bgcolor=#CCCCCC>
			<b><select name=\"act\">
			<option>Please Select</option>
			<option>Mr.</option>
			<option>Ms.</option>
			<option>Mrs.</option>
			</select></b>
		<input type=text size=46 name=text_$i> </td>
	</tr>
	<tr>
		<td align=center colspan=2 bgcolor=#CCCCCC><b>Age No. ($i)</b></td>
		<td bgcolor=#CCCCCC>&nbsp;&nbsp;&nbsp;&nbsp;<input type=text name=age></td>
		
	</tr>
	</table>";
   		
      }

Recommended Answers

All 4 Replies

I presume that you do have a <form> and </form> outside the scope of what you have shown.

In your second module that will receive the fields, you have to treat your $text_n variable as a variable variable unless you want to do a lot of hard coding.

Thus, you will need something like:

$var = "text_"$i;                 
$text = $$var;

You can loop through the range of possible values ($text_0 to $text_n)
and do whatever you wish with each one.

of course i have a <form> and </form/>

$var = "text_"$i;

      $text = $$var;

about on what you wrote, i dont have any idea on how and where to put it..
please help...

It has to go in the module referenced by your form "action".

You will need a loop something like:

$i = 0;
while ($i < xx) {
   $var = "text_"$i;
   $text = $$var;
   echo "<br>The value for item $i is: $text ";
   $i++;
}

If you have a way of knowing when you have reached the end, then you can use it. Otherwise, you'll just have to loop up to some number higher than the max you expect.

Member Avatar for diafol

Something tells me your script won't work as you haven't declared the select names as array items.

<select name = "act[]" ...>

In addition I would suggest using array names for all original widgets - easier for the $_POST variable handling - can count the number of passengers with count(). However there are a number of different ways to do this - you can use the "text_$i" and include a hidden input field with the number of passengers.

Once you choose number of passengers ($i):

...(start of form/table)...
<?php
$j = 0;
while($j < $i){
?>
<tr align=center >
    <td colspan="2" bgcolor="#CCCCCC" width="150">
        <strong>Passenger's Name No. <?php echo $i;?>)</strong>
    </td>
    <td colspan3 bgcolor=#CCCCCC>
        <select name="act[]">
	    <option>Please Select</option>
	    <option value="Mr.">Mr.</option>
	    <option value="Ms.">Ms.</option>
	    <option value="Mrs.">Mrs.</option>
	</select>
        <input type="text" size="46" name="p_name[]" />
    </td>
</tr>
<tr>
    <td align="center" colspan="2" bgcolor="#CCCCCC">
        <strong>Age:</strong>
    </td>
    <td bgcolor="#CCCCCC">
        &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="age[]" />
    </td>
</tr>
<?php
    $j = $j + 1;
}
?>
...(end form/table)...
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.