Gossamer Forum
Home : Products : DBMan : Customization :

Need help in having a dynamic drop down list..

Quote Reply
Need help in having a dynamic drop down list..
I need the ability to pull the listings in a drop down list from a text file. Is there a way i can do this?

What i need is when a user clicks to make a choice on a drop down menu button, that that button will go out and pull the contents of a text file, then display it to the user as viable choices.

Any way I can do this??

Thanks for any help.
Vinnie Lima
Global Management Center
CSC
www.csc.com
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
Try this:

I'm assuming your doing this from html.pl.

Fist end your print statement with |;

Code:
open(SELECT,"/path/to/list/file") | | die "Can't open file";
@list = (<SELECT> );
close (SELECT);

print qq|<select name="name">

foreach $line(@list) {
chomp $line;
print qq|<option>$line</option>|;
print "\n";
}
print qq|</select>|;

Then, resume printing...


Hope this helps,
Chris Ellenburg
webmaster@wfmy.com

------------------
WFMY-TV Webmaster
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
<form method="get" action="db.cgi">
<input type=hidden name="db" value="cook">
<input type=hidden name="uid" value="default">
<input type=hidden name="sb" value="4">
<input type=hidden name="so" value="ascend">
<input type=hidden name="view_records" value="1">
<input type=hidden name="Validate" value="Yes">
<select name="Category" size="1">
<OPTION>Choose a Category:
<option value="Appetizer">Appetizers

</SELECT> <INPUT TYPE="SUBMIT" NAME="view_records" VALUE="GO"></FORM>

The above is saved as catdrop.txt

Then I call the file via an SSI include statement like this:

<!--#include virtual="recdrop.txt"-->

I have this placed in the header of the pages.

Hope this helps Smile

Lois
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
Could you explain a bit more how I can use that script above? i'm not too familiar with scripting...

Here's the sample of my html file (the sub html_record_form):

<TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#80B8DF">

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font>ID:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="ID" VALUE="$rec{'ID'}" SIZE="3" MAXLENGTH="3"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Customer:</FONT></TD>
<TD VALIGN="TOP"> |; print &build_select_field ("Customer", "$rec{'Customer'}"); print qq|</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Location: </FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Location" VALUE="$rec{'Location'}" SIZE="27" MAXLENGTH="255"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Device Name:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Device_name" VALUE="$rec{'Device_name'}" SIZE="27" MAXLENGTH="255"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Node Type:</FONT></TD>
<TD VALIGN="TOP"> |; print &build_radio_field ("Node_type", "$rec{'Node_type'}"); print qq|</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Ignore Type:</FONT></TD>
<TD VALIGN="TOP"> |; print &build_radio_field ("Ignore_type", "$rec{'Ignore_type'}"); print qq|</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Interface Number:</FONT></TD>
<TD VALIGN="TOP"> |; print &build_select_field ("Interface_number", "$rec{'Interface_number'}"); print qq|</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Date:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Date" VALUE="$rec{'Date'}" SIZE="12" MAXLENGTH="12"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Time:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Time" VALUE="$rec{'Time'}" SIZE="12" MAXLENGTH="12"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Description:</FONT></TD>
<TD VALIGN="TOP"> <TEXTAREA NAME="Description" ROWS="4" COLS="40" WRAP="VIRTUAL" MAXLENGTH="255">$rec{'Description'}</TEXTAREA></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>From Date:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Date_from" VALUE="$rec{'Date_from'}" SIZE="12" MAXLENGTH="12"><TD VALIGN="TOP"><$font>To Date:</font><INPUT TYPE="TEXT" NAME="Date_to" VALUE="$rec{'Date_to'}" SIZE="12" MAXLENGTH="12"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Requested By:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Requested_by" VALUE="$rec{'Requested_by'}" SIZE="30" MAXLENGTH="255"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Phone#:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Phone" VALUE="$rec{'Phone'}" SIZE="13" MAXLENGTH="255"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>GMC Analyst:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="GMC_Analyst" VALUE="$rec{'GMC_Analyst'}" SIZE="30" MAXLENGTH="255"></TD></TR>


</TABLE>
|;
}



I would like to use the script above on the "Device_name" and "Node_type"

Thanks again for any help..

Vinnie
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
Make sure you take the space out from between the pipes in
Code:
open(SELECT,"/path/to/list/file") &#0124; &#0124; die "Can't open file";
the board puts them there.

replace "/path/to/list/file" with the complete PATH, not URL, to the relevant text file. The text file should be formatted as this:
Code:
selection 1
selection 2
selection 3
with a carriage return after each item. Make sure that the permissions are set correctly on these files (644).


Code:
<TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#80B8DF">

<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="150"><$font>ID:</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <INPUT TYPE="TEXT" NAME="ID" VALUE="$rec{'ID'}" SIZE="3" MAXLENGTH="3"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Customer:</FONT></TD>
<TD VALIGN="TOP"> |; print &build_select_field ("Customer", "$rec{'Customer'}"); print qq|</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Location: </FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Location" VALUE="$rec{'Location'}" SIZE="27" MAXLENGTH="255"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Device Name:</FONT></TD>
<TD VALIGN="TOP">|;

open(SELECT,"/path/to/list/file") &#0124; &#0124; die "Can't open file";
@device_list = (<SELECT> );
close (SELECT);
print qq|<select name="Device_name">|;
foreach (@device_list) {
chomp $_;
print "<option";
print " SELECTED" if ($rec{'Device_name'} eq "$_");
print ">$_\n";
}
print qq|</select>

</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Node Type:</FONT></TD>
<TD VALIGN="TOP"> |;

open(SELECT,"/path/to/list/file") &#0124; &#0124; die "Can't open file";
@node_list = (<SELECT> );
close (SELECT);
print qq|<select name="Node_type">|;
foreach (@node_list) {
chomp $_;
print "<option";
print " SELECTED" if ($rec{'Node_type'} eq "$_");
print ">$_\n";
}
print qq|</select>



</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Ignore Type:</FONT></TD>
<TD VALIGN="TOP"> |; print &build_radio_field ("Ignore_type", "$rec{'Ignore_type'}"); print qq|</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Interface Number:</FONT></TD>
<TD VALIGN="TOP"> |; print &build_select_field ("Interface_number", "$rec{'Interface_number'}"); print qq|</TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Date:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Date" VALUE="$rec{'Date'}" SIZE="12" MAXLENGTH="12"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Time:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Time" VALUE="$rec{'Time'}" SIZE="12" MAXLENGTH="12"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Description:</FONT></TD>
<TD VALIGN="TOP"> <TEXTAREA NAME="Description" ROWS="4" COLS="40" WRAP="VIRTUAL" MAXLENGTH="255">$rec{'Description'}</TEXTAREA></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>From Date:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Date_from" VALUE="$rec{'Date_from'}" SIZE="12" MAXLENGTH="12"><TD VALIGN="TOP"><$font>To Date:</font><INPUT TYPE="TEXT" NAME="Date_to" VALUE="$rec{'Date_to'}" SIZE="12" MAXLENGTH="12"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Requested By:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Requested_by" VALUE="$rec{'Requested_by'}" SIZE="30" MAXLENGTH="255"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>Phone#:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="Phone" VALUE="$rec{'Phone'}" SIZE="13" MAXLENGTH="255"></TD></TR>

<TR><TD ALIGN="Right" VALIGN="TOP"><$font>GMC Analyst:</FONT></TD>
<TD VALIGN="TOP"> <INPUT TYPE="TEXT" NAME="GMC_Analyst" VALUE="$rec{'GMC_Analyst'}" SIZE="30" MAXLENGTH="255"></TD></TR>


</TABLE>
|;
}

------------------
WFMY-TV Webmaster
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
Thank you!!!!!

Works perfectly!!

Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
Chris, I installed your little script for the drop down text, and it works perfectly except for one thing. When I add a record, it's great, when I do a search for a record (I replaced the first line of text with a "*" so people were not FORCED to match that field), so it searches fine also, but if I modify any record, then the field gets replaced by the "*" again. Is there any way that it can retain the old records information?

I'm running on UNIX, on an Intranet. I can't get you a link to the database sorry. The information is EXACTLY as you had posted.

Thanks in adavance,
Conor
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
My suggestion would be, don't use "*". Instead, do this:
Code:
print qq|<select name="Node_type"><option>|;
foreach (@node_list) {
chomp $_;
print "<option";
print " SELECTED" if ($rec{'Node_type'} eq "$_");
print ">$_\n";
}
print qq|</select>

Notice I added the blank option. If this doesn't work, please post a url to your cfg file and html.pl file as text. Also note that the $rec{'Node_type'} should be replaced with the same name you have in the select field.

So if the name of your select field was SAM:
Code:
<select name="SAM">
Then you should also have:
Code:
print " SELECTED" if ($rec{'SAM'} eq "$_");

------------------
Chris
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
Chris,
Here's an update on the situation.
I tried the addition of the <option> but it still didn't work. Here's what I had:
Code:
open<(SELECT,"/path/to/file.txt")&#0124; &#0124; die "Can't open file";
@station_list = (<SELECT> );
close (SELECT);
print qq|<select name="Station Name"><option>|;
foreach (@station_list){
chomp $_;
print "<option";
print "SELECTED" if ($rec{'Station Name'} eq "$_");
print ">$_\n";
}
print qq|</select>
|;
I changed it to read the following
Code:
open(SELECT,"/path/to/file.txt")| | die "Can't open file";
@station_list = (<SELECT> );
close (SELECT);
print qq|<select name="Station Name">|;
foreach (@station_list){
chomp $_;
print qq| <option>$rec{'Station Name'}</option>|;
print "$_\n";
}
print qq|</select>
I added a blank line to the first line of the text file for the list, and everything works now. I guess in removing the line reguarding SELECTED and adding the blank line, it fixed itself.

Thanks again for your help, I'll continue to muddle with DBMan as always Smile

Leprechaun
Conor

[This message has been edited by Leprechaun (edited January 17, 2000).]
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
I don't know how in the world that works, unless you only have 1 option. To do it correctly, you must do it like this.
Code:
open<(SELECT,"/path/to/file.txt") or die "Can't open file";
@station_list = (<SELECT> );
close (SELECT);
print qq|<select name="Station Name"><option>|;
foreach (@station_list){
chomp $_;
print "<option";
print " SELECTED" if ($rec{'Station Name'} eq "$_");
print ">$_\n";
}
print qq|</select>|;

Please notice the space between the " and the word SELECTED. This maybe why it wasn't working for you. Good luck!


------------------
Chris
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
And here I thought I had it exactly the same. I didn't notice the space!

Not to worry, it's still working. The reason
that I had to use your script was because DBMan limited me to about 450 items in the drop down. I have 862! Surprise surprise, everything is perfect! But today is a new day. I'll keep your message on file "just in case", but until it breaks, I'll let it go as is.

Thanks again for your help

Conor
Quote Reply
Re: Need help in having a dynamic drop down list.. In reply to
This topic has been continued at the following location:
http://www.gossamer-threads.com/...m12/HTML/002323.html

------------------
Conor Treacy
www.handsonwebdesign.com