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!

ListBox - Selecting a value in code

Status
Not open for further replies.

netcashin

Programmer
Nov 13, 2000
159
0
0
US
Ok, here is an easy one, but I am beating my brain in trying to figure it out.

I have a list box that is populated with items and with values. A value is passed to the form and as it is loaded I wish to have the item selected with corresponding value.

I have searched and searched and can't find the answer. (and I know it is a simple one which makes it more frustrating)

Help ???? Thanks in advance.

Thanks in adance for any help.
 
Do you mean this?

<select name=&quot;MyListBox&quot;>
<cfoutput query=&quot;MyQuery&quot; <cfif MyValue eq Form.MyListBox>selected</cfif>>
<option value=&quot;#MyValue#&quot;>#MyItem#</option>
</cfoutput>
</select>


chau
 
I think you are on the right track. Let me give a little more detail. The list box is hard coded.

<Select name=&quot;Consequence1&quot;>
<option value=&quot;5&quot;>Choice5</option>
<option value=&quot;4&quot;>Choice4</option>
<option value=&quot;3&quot;>Choice3</option>
<option value=&quot;2&quot;>Choice2</option>
<option value=&quot;1&quot;>Choice1</option> </Select> </td>

Value #MyValue# is passed from another from. I wish for the item to be selected from the list box with the corresponding value equal to #MyValue#.
 
something like this?
<cfparam name=&quot;form.MyPassedValue&quot; default=&quot;5&quot;>
<Select name=&quot;Consequence1&quot;>
<option value=&quot;5&quot; <cfif form.MyPassedValue eq 5>selected</cfif>>Choice5</option>
<option value=&quot;4&quot; <cfif form.MyPassedValue eq 4>selected</cfif>>Choice4</option>
<option value=&quot;3&quot; <cfif form.MyPassedValue eq 3>selected</cfif>>Choice3</option>
<option value=&quot;2&quot; <cfif form.MyPassedValue eq 2>selected</cfif>>Choice2</option>
<option value=&quot;1&quot; <cfif form.MyPassedValue eq 1>selected</cfif>>Choice1</option> </Select>

chau
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top