Select List Box from Array

D

dthmtlgod

I have a string that was populated from a listbox.
Now I want to bring up the record again for edit and want the listbox to
have those records selected ONLY. I am close I think. Currently, it
selects all records.

<%
HearingIssues = RS3(0)
HI = Split(HearingIssues, ",", -1, 1)

For i = 0 to ubound(HI,1)
sString = Instr(HearingIssues,HI(I))
if sString = 0 then
%>
<option value="<%= HI(I)%>"><%=HI(I) %></option>
<% else %>
<option value="<%= HI(I)%>" selected><%= HI(I) %></option>
<% end if
next
 
L

Larry Bud

I have a string that was populated from a listbox.
Now I want to bring up the record again for edit and want the listbox to
have those records selected ONLY. I am close I think. Currently, it
selects all records.

<%
HearingIssues = RS3(0)
HI = Split(HearingIssues, ",", -1, 1)

For i = 0 to ubound(HI,1)
sString = Instr(HearingIssues,HI(I))
if sString = 0 then
%>
<option value="<%= HI(I)%>"><%=HI(I) %></option>
<% else %>
<option value="<%= HI(I)%>" selected><%= HI(I) %></option>
<% end if
next%>

I don't see your <SELECT> tag, are you allowing multiple select?

where it says "selected" you need to see if HI(I) is INSTR your
variable, and if it is, response.write("selected")
 
D

dthmtlgod

Here is the code with the SELECT statement. It is still selecting the
entire list box.


<select name="HearingIssues" size="11" multiple style="width: 250px;">
<%
While NOT RS3.EOF
HearingIssues = RS3(0)
HI = Split(HearingIssues, ",", -1, 1)

For i = 0 to ubound(HI,1)
sString = Instr(HearingIssues,HI(I))
if sString = 0 then
%>
<option value="<%= HI(I)%>"><%=HI(I) %></option>
<% else %>
<option value="<%= HI(I)%>" selected><%= HI(I) %></option>
<%
end if
next

RS3.MoveNext
WEND
%>
</select>
 
L

Larry Bud

dthmtlgod said:
Here is the code with the SELECT statement. It is still selecting the
entire list box.


<select name="HearingIssues" size="11" multiple style="width: 250px;">
<%
While NOT RS3.EOF
HearingIssues = RS3(0)
HI = Split(HearingIssues, ",", -1, 1)

For i = 0 to ubound(HI,1)
sString = Instr(HearingIssues,HI(I))
if sString = 0 then
%>
<option value="<%= HI(I)%>"><%=HI(I) %></option>
<% else %>
<option value="<%= HI(I)%>" selected><%= HI(I) %></option>
<%
end if
next

RS3.MoveNext
WEND
%>
</select>

You need to debug in steps:
It would be selecting every entry in the select box if the "if
sString=0" statement is always false.

So let's look at sString. It's set with Instr function:
sString = Instr(HearingIssues,HI(I))

We know sString is always being set to a non-zero, right? A non zero
occurs when 1) the first string is null, 2) the second string is null,
or string2 is found within string1.

So how about printing out the values for hearingissues, and HI(i)??

Also, why are you using Instr? When you're looping through your
recordset, aren't you looping through all possible single values for
hearingissues?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top