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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Newbie understand Listboxes 1

Status
Not open for further replies.

puterdude

Technical User
Apr 13, 2001
51
0
0
US
Hi,
This may be a dumb question, but I'm having trouble understanding the behavior of listboxes. I have a list of say 3 items: Bananas
Apples
Grapes
I wish to allow mutliple selections and I can do that no problem.

I set the values for Bananas at B
Apples at A
Grapes at G
I am assuming that if the user chooses bananas and grapes, and hits submit, the field will hold BG (text field in access). True?
If the user returns to the page to change their mind, it would be nice to see that Bananas and Grapes are still highlighted and allow them to unclick their choice or choices.

When I tried it the list seemed to populate with the value rather than the original label. It was weird. Had the labels but the value was added to the bottom with a comma after it ie. B, and that's all.

I'm missing something here I'm sure, but if you could shed some light on this I would greatly appreciate it.

Thank you.

Puterdude


 
>I am assuming that if the user chooses bananas
>and grapes, and hits submit, the field will hold BG.
False.
B,G



EG
listbox1.htm:

<form method=post action=listbox2.asp>
<select multiple name=fruit>
<option value=A>Apples
<option value=G>Grapes
<option value=B>Bananas
</select>
<input type=submit>
</form>

listbox2.asp:
dim cFruit
cFruit = Request.Form(&quot;fruit&quot;)
Response.Write cFruit & &quot;<br>&quot;
response.Write &quot;<select multiple name=fruit>&quot;
Response.Write &quot;<option value=A&quot;
if InStr(cFruit, &quot;A&quot;) then Response.Write &quot; selected&quot;
Response.Write &quot;>Apples&quot;
Response.write &quot;<option value=G&quot;
if InStr(cFruit, &quot;G&quot;) then Response.Write &quot; selected&quot;
Response.Write &quot;>Grapes&quot;
Response.Write &quot;<option value=B&quot;
if InStr(cFruit, &quot;B&quot;) then Response.Write &quot; selected&quot;
Response.Write &quot;>Bananas&quot;
Response.Write &quot;</select>&quot;



br
Gerard
 
Thanks a lot. I didn't know about the , issue. I was using frontpage previously and it didn't do that.

Do you know if it is difficult to break up/out the listbox data to send in a Jmail email? I would like to send the email with the data already separated,
ie. Fruit 1: G
Fruit 2: A etc.

thanks again
 
dim cFruit
cFruit = Request.Form(&quot;fruit&quot;)
Response.Write cFruit & &quot;<br>&quot;

dim n,i
i = 1
while len(cFruit)>0
n = len(cFruit)
Response.Write &quot;Fruit &quot; & i & &quot;: &nbsp;&quot; &_
left(cFruit,1) & &quot;<br>&quot;
cFruit = trim(mid(cFruit,3,n))
wend br
Gerard
 
Gerard,

Only now got back to the listbox coding and I dont now where to put it. The form is an update form in asp.
When I show the field Fruit on the form it shows A,C if I selected the first and 3rd items, but the list is not highlighted for those items.

The code I entered is:
dim cfruit
cfruit = rs_update.fields.item(&quot;fruit&quot;).value

response.Write &quot;<select multiple name=fruit>&quot;
Response.write cFruit & &quot;<br>&quot;
Response.Write &quot;<option value=A&quot;
if InStr(cFruit, &quot;A&quot;) then Response.Write &quot; selected&quot;
Response.Write &quot;>Apples&quot;
Response.write &quot;<option value=G&quot;
if InStr(cFruit, &quot;G&quot;) then Response.Write &quot; selected&quot;
Response.Write &quot;>Grapes&quot;
Response.Write &quot;<option value=B&quot;
if InStr(cFruit, &quot;B&quot;) then Response.Write &quot; selected&quot;

where does this code go in the form?

I know its me, but why?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top