PDA

View Full Version : Uisng a default value in a Combo Box


Ruk
08-05-2005, 12:00 PM
Hi,
I'm helping to customize a help desk system written in Perl.
The system propmts the user for his company name (Our company is a conglomerate with many subsidiaries). This is stored in a MySQL database in a table named "customer_user" (field named "company_name").
When a user logs in an issue the value stored in the "company" field must be set as the default value in the combo box named "company :". So for each user the default value set in the combo box will depend on the company he was working at when he first registered.
I wish to know the code segment that will help me retrieve the company name from the database.
Thanks
Ruk

Hostultrix
08-06-2005, 07:59 AM
You'd want to test each company name with that retrieved by the database, and if they matched, output the appropriate HTML to make that the default option. Let's assume $company_name holds the name of the company that customer is posting about, and @companies is an array of all possible company names.

print "<select name=\"company\">\n";
foreach (@companies) {
print "<option"
.($_ eq $company_name
? " selected" : '')
.">$_</option>\n";
}
print "</select>\n";

If you don't know how to retrieve the data, you may want to study up on DBI (http://dbi.perl.org) and MySQL (http://www.mysql.com).

Brandon