Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing the Text Instead of the Value

Status
Not open for further replies.

duckiebear

Programmer
May 25, 2004
32
0
0
US
Hello, I am trying to print the text that is printed in the drop down menu rather than the value. I have a form that is populated by the data contained in this form (including the selectedIndex of drop down menus) and it prints both the key and the text associated with the selectedIndex. Any suggestions? Here is my code:


Code:
%us_states = ("alabama", "Alabama", "alaska", "Alaska", "arkansas", "Arkansas", "wyoming", "Wyoming");

foreach $state_list (sort keys %us_states) {
     $us_states_options = "$us_states_options<option value=$state_list>$us_states{$state_list}";
     }

# for my create record form
#this line will give the text_state_incorp the text value as its value

print "<td align=left><font size=-1>State Incorporated</td><td><select name=state_incorp onChange=\"text_state_incorp.value = state_incorp.options[state_incorp.selectedIndex].text\"<option value=null>Choose State$us_states_options</select><input type=hidden name=text_state_incorp></font></td><tr>\n";

#for update record form
#this field will not populate as desired and print to the html form that is generated upon clicking a "submit" button on the update page.

if ($state_incorp_alt) {
     $state_incorp_default_options = "$state_incorp_default_options<option value=\"$state_incorp_alt\" selected>$us_states{$state_incorp_alt}";
     $state_incorp_alt = "$state_incorp_alt<br>&nbsp;$us_states{$state_incorp_alt}";
     $state_incorp_alt =~ s/^<br>//g;

     }
$state_incorp_default_options = "$state_incorp_default_options<option value=\"null\">...";

print "<input type=hidden name=state_incorp value=\"$state_incorp_alt\">\n";

print "<input type=hidden name=text_state_incorp value=\"$text_state_incorp_alt\">\n";

print "<td><font size=-1>State Incorporated </td><td><select name=state_incorp>$state_incorp_default_options$us_states_options</select><input type=hidden name=text_state_incorp value=\"state_incorp_alt\"></td><tr>\n";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top