How do I get selected value from drop down box in

2019-08-27 15:09发布

问题:

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.