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

时间秒杀一切 提交于 2019-12-13 06:02:51

问题


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');

回答1:


You are missing name="client_name" in the select tag.

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.



来源:https://stackoverflow.com/questions/15095511/how-do-i-get-selected-value-from-drop-down-box-in-perl-cgi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!