Getting the selected element in select

Tell me, please. How to get selected element from select? To the optionvariable, for example.


Answer 1, authority 100%

<?
$opt = intval(!empty($_GET['opt']) ? $_GET['opt'] : 0);
if (!$opt) {
?>
<form method="post">
<select name="opt" onchange="this.form.submit()">
  <option value="0" selected="selected"></option>
  <option value="1"> </option>
  <option value="2"> </option>
</select>
</form>
<? } else { ?>
: <?=$opt?>
<? } ?>

Answer 2

Well, for starters, I would advise you to screw the submit button into the form 🙂 Let me ask you, is this your working code or just a couple of unseparated pieces?


Answer 3

<?php
$option = isset($_GET['option']) ? (int) $_GET['option'] : 1;
echo $option;
?>
<form id="formazak" method="get"> <br /><br />
  :
<select name="option">
<option value="1"> </option>
<option value="2"> </option>
</select>
<input type="submit">
</form>