TOM
TOM

Reputation: 881

how can i get the selected value of dropdown list in php?

i have seen several question but i can not find any answer? i am add a some value to dropdown through the loop and want to show the value when i select one value from dropdown box .but i can not find .

  $items[] = $file ;
  echo '<select name="value">';
  foreach($items as $video){ 
    echo  '<option value="' . $video . '">' . $video . '</option>' ;
  }
  echo '</select>';
  $value = $_GET['footage'];

How can I get the value when I select some value in the dropdown box.

Upvotes: 0

Views: 62

Answers (1)

Pupil
Pupil

Reputation: 23958

You need to add HTML selected attribute to <select>

$value = $_GET['footage']; /* typo*/
 $items[] = $file ;
  echo '<select name="value">';
  foreach($items as $video){ 
    $selected = ($value == $video) ? 'selected="selected"' : '';
    echo  '<option value="' . $video . '"' . $selected . '>' . $video . '</option>' ;
  }

  echo'</select>';

Upvotes: 1

Related Questions