Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array of HTML select

Status
Not open for further replies.

alsaffar

Programmer
Joined
Oct 25, 2001
Messages
165
Location
KW
Hi there,

I want to show each HTML select value after submitting the form. How?

<? if (isset($_POST[submit]))
{
for ($i=1; $i<=10; $i++) echo "$i:$_POST[TestSelect][$i]<br>";
}
?>
<form method='post' name='TestForm' action='<? echo $_SERVER[PHP_SELF] ?>'>
<? for ($i=1; $i<=10; $i++)
{?><select name='TestSelect[<? echo $i ?>]'><option value='A'>A</option><option value='B'>B</option></select><?}?>
<input type='submit' name='submit'>
</form>
 
You almost have it:
Code:
<?
if (isset($_POST['submit']))
    for ($i=1;$i<10;$i++)
        echo $i.':'.$_POST['TestSelect'][$i]."<br>\n";
?>

If this does not work, what problems are you seeing?

Ken
 
Come on guys please help :(
 
well..

after cleaning up your code:
Code:
<form method="post" name="TestForm" action="<?=$_SERVER[PHP_SELF]?>">
<? for ($i=1; $i<=10; $i++) {
   echo "<select name=\"TestSelect\">
           <option value='A'>A</option>
           <option value='B'>B</option>
         </select>
   }
?>
<input type="submit" name="submit">
</form>

I find my self scratching my head.
What do you want to perform here?

You are generating 10 x input forms, with 1 x select, containing 2 options in each.

* Why do you use array for this?
* What type of data do you wish to let the user submit?
* Is it multiple select options?

I think that you want your loop inside the <select>, not outside, so you loop options, not selects.

however, since you give us too little information, it's hard to help you more.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top