什么“类型”是从选择标签中选择的选项 [英] what "type" is an option chosen from a select tag

查看:95
本文介绍了什么“类型”是从选择标签中选择的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP新手,尝试获取从选择标记中选择的选项的值。我熟悉一些输入类型,如广播,文本,复选框e.t.c.我的问题是type是从选择标记中选择的选项。前三个表格工作得很好,但不是第四个
,这里是我的代码

I am new to PHP and attempting get the value of an option chosen from a select tag. I am familiar with some types of input such as radio, text, checkboxes e.t.c. my question is what "type" is an option chosen from a select tag. The first three forms work just fine but not the fourth here is my code

<form action = display.php method="get">
input first name:
<input type=text name=fname><br>
input last name:
<input type=text name=lname><br>
<input type=submit value="Click">
</form>

<form name="input"
action=radio.php method="get">
Username:<input type="text" name="user">
<br>
<input type=radio name=card_type value="visa ">
Visa <br>
<input type=radio name=card_type value="mc">
Master Card <br>
<input type="radio" name=card_type value="discover">
Discover <br>
<input type="submit" value="Submit"/>
</form>

<form name="gender"
action=gender.php method="get">
<input type=radio name=gender_type value="male">
Male <br>
<input type=radio name=gender_type value="female">
Female <br>
<input type="submit" value="Submit"/>
</form>

<form name="chosen_party" action=party.php method="get">
<select>
<option type=text  name=party_type value="democrat">Democrat</option>
<option type=text  name=party_type value="republican">Republican</option>
<option type=text  name=party_type value="independent">Independent</option>
<option type=text  name=party_type value="undecided">Undecided</option> 
</select>
<input type=submit value="Submit">
</form>

以及第四种形式的PHP文件...

and the PHP file for the fourth form...

<?php
$party_select = $_GET['party_type'];
echo "User has chosen $party_select";
?>       


推荐答案

首先为选择标签命名。并在选择权的情况下给每个选项赋予一个值。像这样..

First give a name to select tag. and in the case of option give a value to each option. like this..

<form name="chosen_party" action=party.php method="get">
<select name="party_type">
<option   value="democrat">Democrat</option>
<option   value="republican">Republican</option>
<option   value="independent">Independent</option>
<option   value="undecided">Undecided</option> 
</select>
<input type=submit value="Submit">
</form>

然后在php中有一个小小的语法问题。您必须将$ party_select放在引号之外。代码应该是..

Then in the php there is a little syntax problem. You have to put $party_select outside of the quote. The code should be..

<?php
$party_select = $_GET['party_type'];
echo 'User has chosen '.$party_select;
?>

希望这会有所帮助..

Hope this helps..

这篇关于什么“类型”是从选择标签中选择的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆