如何从Perl CGI的下拉框中获取选定的值 [英] How do I get selected value from drop down box in Perl CGI

查看:219
本文介绍了如何从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');


推荐答案

您缺少 name = client_name在选择标记中。

您可能应该在value属性中转义客户端名称(尽管对于United Dynacare而言,它不是没有必要)。使用库来生成HTML(例如, CGI )会对这两件事情有所帮助。

You probably ought to be escaping the client name in the value attribute (though for United Dynacare it isn't necessary). Using a library to generate your HTML (for instance, CGI) would have helped with both of these things.

这篇关于如何从Perl CGI的下拉框中获取选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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