Link to home
Start Free TrialLog in
Avatar of ragnarok89
ragnarok89

asked on

Determine selected element number

Hi All,

I have a dropdown box on a form that lists countries:

 
$lines =file('./Countries.csv');
foreach($lines as $data) {
   list($countriesAr[],$Continent[],$Notify[]) = explode(',',$data);
}

for($i=0;$i<count($countriesAr);$i++) {
     echo "<option value='".$countriesAr[$i]."'";
     if($_POST['country'] ==  $countriesAr[$i]) 
          echo "SELECTED";
     echo ">".$countriesAr[$i]."</option>\n";
}

Open in new window


My question is, when the form get submitted, I want to know which country was chosen, i.e. the first on the list, or 12th, etc. I need to know the element number. How do I get that value?

Al
ASKER CERTIFIED SOLUTION
Avatar of Ahmed Merghani
Ahmed Merghani
Flag of Sudan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just curious - why does the number of the selection matter?  I cannot think of any design pattern that would work that way.  It's potentially very brittle - what if the number or order of the countries changed?  If you have code that depends on a numeric position in an array from an external source (like $_POST) you may be accepting too much risk.  Just a thought.
http://php.net/manual/en/tutorial.forms.php
Avatar of ragnarok89
ragnarok89

ASKER

fishboy2000sd,

   Worked like a charm; thank you.

Al
You are welcome