开发者

php how to grab the selected value from a drop down list?

<select name="gamelist" id="gamelist">
<option value=开发者_运维问答"1">Backgammon</option>
<option value="2">Chess</option>
</select>
<input type="submit" name="submit" id="submit" value="Submit" />

i want to grab the selected value and place in in a var any idea? thanks


Depends on your form tag.

<form method="post">

Will pass the value to $_POST['gamelist']

While

<form method="get">

Will pass the value to $_GET['gamelist']

Ofcourse, only after hitting the submit button. As morgar stated, this is pretty basic form procession. I doubt you've used google or followed a tutorial, this is almost one of the first things one learn when working with forms and PHP. We arent here to give you full solutions, take this as an example and create the full page yourself:

if($_SERVER['REQUEST_METHOD'] == "Y") {
  $choice = $_Y['gamelist'];
  // other stuff you want to do with the gamelist value
} else {
  echo '<form method="Y" action="file.php">';
  // the rest of your form
  echo '</form>';
}

Replace Y with either GET or POST.


 $choice = $_REQUEST['gamelist']; //works with get or post


$choice = $_POST['gamelist']

if it is a POST, or $_GET if not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜