简体   繁体   English

如何从Perl CGI的下拉框中获取选定的值

[英]How do I get selected value from drop down box in Perl CGI

I am populating the drop down menu from database. 我正在从数据库填充下拉菜单。 And when I submit the form I am getting empty string in selected option. 当我提交表格时,我在选择的选项中得到空字符串。 Here's my code any help will be appreciated. 这是我的代码,任何帮助将不胜感激。 I have selected the first option as default any help. 我选择了第一个选项作为默认的任何帮助。

print "<br>Name: <select>";
while ( my ($name) = fetchrow_array() ) {
    if ($name eq "Somethinge") {
        print "<option value=\"$name\" selected>" . $name . "</option>\n";
    }else {
        print "<option value=\"$name\">" . $name . "</option>\n";
        }
}
print "</select>";

I am getting the value using below but its returning empty whatever I select. 我正在使用下面的值,但无论我选择什么,它都返回空。

my $Name = param('name');

You are missing name="client_name" in the select tag. 您在选择标记中缺少name="client_name"

You probably ought to be escaping the client name in the value attribute (though for United Dynacare it isn't necessary). 您可能应该在value属性中转义客户名称(尽管对于United Dynacare没有必要)。 Using a library to generate your HTML (for instance, CGI ) would have helped with both of these things. 使用库来生成您的HTML(例如CGI )将对这两个方面都有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM