Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting the values from a list box

9 views
Skip to first unread message

Cezar

unread,
Jul 11, 2001, 9:01:47 AM7/11/01
to

Hi guys,
I know it's more a HTML question but anyway:
I have a listbox filled from DB and I have multiple choice
option. When I try to get the values selected I only get the
first one either using POST or GET,
Request.ContentFields.Values['field_name'] or Request.QueryString.Values['field_name']

Any idea what should I do or what am I doing wrong???

TIA,
Cezar

Christoph Bubestinger

unread,
Jul 11, 2001, 9:29:32 AM7/11/01
to
> When I try to get the values selected I only get the
> first one either using POST or GET,
> Request.ContentFields.Values['field_name'] or
> Request.QueryString.Values['field_name']

.Values only returns the first occurence. you´ll have to loop through the
.Names[Index] property to get all values. shouldn´t be too much of a
problem, you are handling a TString object, read the delphi doc´s on that,
it should look like this in your case:

foo=valuefoo
field_name=value1
field_name=value2
field_name=value3
humptydumpty=valueegg
.
.
.

christoph

Cezar

unread,
Jul 11, 2001, 10:18:31 AM7/11/01
to

Many thanks Christoph,

I can't play with the .Names[Index] because before
displaying the listbox I have dynamically generated fields and
I'm don't know what's the index for the listbox.


Cezar

>..Values only returns the first occurence. you惻l have to loop through the
>..Names[Index] property to get all values. shouldn愒 be too much of a
>problem, you are handling a TString object, read the delphi doc愀 on that,


>it should look like this in your case:
>
>foo=valuefoo
>field_name=value1
>field_name=value2
>field_name=value3
>humptydumpty=valueegg
>..

>..
>..
>
>christoph
>
>
>

Shiv Kumar

unread,
Jul 11, 2001, 12:07:42 PM7/11/01
to
The name will be the name of your listbox, but there may be multiple entries
for this name. So you'll have to loop through ContentFields or QueryFields
as the case may be and get the number of times the "name" was present.

Here is some code I've used in the past....

procedure TWebModule1.ExtractMultipleSelectionValues(RequestField: string;
var MultipleValues: TStrings);
var
i: Integer;
tempList: TStrings;
begin
{ Since the ContentFields contains duplicate name/value pairs (only names
are duplicate)
I've had to use a tempList to add matching RequestField name/value to
and then
immideately put the value into MultipleValues list
}
tempList := TStringList.Create;
try
MultipleValues.Clear;
for i := 0 to Request.ContentFields.Count -1 do
if Request.ContentFields.Names[i] = RequestField then
begin
tempList.Clear;
tempList.Add(Request.ContentFields[i]);
MultipleValues.Add(tempList.Values[tempList.Names[0]]);
end;
finally
FreeAndNil(tempList);
end;
end;

Not sure why I used the logic I did, but it worked <g>

--
Shiv Kumar
The Delphi Apostle
http://www.matlus.com
http://www.delphisoap.com


Mike Mader

unread,
Jul 11, 2001, 1:13:20 PM7/11/01
to
I also took a go at writing a function to return multiple values from a
list box. Just as I finished my version, and was showing it to a co-worker,
I saw Shiv posted one too. I thought I would post mine too. It works a
little differently than Shiv's, but it also automatically works between Post
and Get. Here it is:

function GetMultipleSelect(fieldname :string):TStrings;
var
values :TStrings;
count :integer;
value :string;
webfieldname :string;
fieldcount :integer;
begin
values := TStringList.Create;
values.Clear;
count := 0;

if Request.MethodType = mtPOST then
fieldcount := Request.ContentFields.Count
else
fieldcount := Request.QueryFields.Count;

while count < fieldcount do
begin
if Request.MethodType = mtPOST then
webfieldname := lowercase(Request.ContentFields.Names[count])
else
webfieldname := lowercase(Request.QueryFields.Names[count]);

if webfieldname = lowercase(fieldname) then
begin
if Request.MethodType = mtPOST then
value := Request.ContentFields[count]
else
value := Request.QueryFields[count];

delete(value, 1, pos('=', value));
values.Add(value);
end;
count := count + 1;
end;

Result := values;
end;

ndsh...@gmail.com

unread,
Aug 31, 2012, 7:46:30 AM8/31/12
to Cezar
On Wednesday, 11 July 2001 19:56:54 UTC+5:30, Cezar wrote:
> Many thanks Christoph,
>
> I can't play with the .Names[Index] because before
> displaying the listbox I have dynamically generated fields and
> I'm don't know what's the index for the listbox.
>
>
> Cezar
>
> >..Values only returns the first occurence. you´ll have to loop through the
> >..Names[Index] property to get all values. shouldn´t be too much of a
> >problem, you are handling a TString object, read the delphi doc´s on that,
> >it should look like this in your case:
> >
> >foo=valuefoo
> >field_name=value1
> >field_name=value2
> >field_name=value3
> >humptydumpty=valueegg
> >..
> >..
> >..
> >
> >christoph
> >
> >
> >

Thank you so much ... I am wondering for this solution.. tried it and worked...thanks again
0 new messages