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!

Compare value in listbox ???

Status
Not open for further replies.

bkyeong

MIS
Aug 7, 2002
6
0
0
US
Currently, I have a list box with
<select name=&quot;test&quot;>
<option value=&quot;&quot;></option>
<option value=&quot;122&quot;>122</option>
</select>

now i would like to compare the value that store in
a database called TEMP with the value above.
if the value that query from the database is e.g 999, i would like the listbox to display the value.
O the other hand, If the value that query from the database is e.g 122, i just wish the listbox display the default value in the HTML form above.
Pls help. Thank you so much

 
i'm not sure if i understand this correctly.
by adding &quot;selected&quot; to 1 (one) of the options you make it &quot;default&quot;.
And you can add additional <options> based on any IF you want.

like this:


<select name=&quot;test&quot;>
<option value=&quot;&quot;
<%
if val <> 999 then response.write &quot; selected &quot;
%>
></option>
<option value=&quot;122&quot;>122
<%
if val = 999 then
response.write &quot;<option>999&quot;
end if
%>
</select>



hth,
Foxbox
ttmug.gif
 
Hi Foxbox, thanks for ur reply.
I think the statement below will make the question more Understandable.
*p/s: 999 is a variable.........

Currently, I have a list box with
<select name=&quot;test&quot;>
<option value=&quot;100&quot;>100</option>
<option value=&quot;122&quot;>122</option>
</select>

now i would like to compare the value that store in
a database called TEMP with the value above.
if the value that query from the database is e.g 999, i would like the listbox to display the value. .(The list box will show &quot;100&quot;,&quot;122&quot;,&quot;999&quot;)
On the other hand, If the value that query from the database is e.g 122, i just wish the listbox display the default value in the HTML form above.(The list box will show &quot;100&quot;,&quot;122&quot;)
Pls help. Thank you so much

 
' nValue1 is the value from the database

<select name=&quot;test&quot;>
<option>100
<option>122
<%
if nValue1 = 999 then
response.write &quot;<option>999&quot;
end if
%>
</select>


hth,
Foxbox
ttmug.gif
 
Hi,
I have 2 suggestions.

1. If you know that only a limited values are like this, query the table such a way to exclude these values. then you can loop thro' to insert the new values.

<select name=&quot;test&quot;>
<option>100
<option>122
<%for i ....
if nValue1 = 999 then
response.write &quot;<option>999&quot;
end if
next i
%>
</select>


2. if you will know the values only after the table is queried, get that in an array. say you will have arr(1)=100, arr(2)=122.
now you can say

if arr(i) <> nvalue1 then
<option > 999
end if

Hope you got what i say.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top