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

Populate combo box after selection problem

Status
Not open for further replies.

Gill1978

Programmer
Joined
Jun 12, 2001
Messages
277
Location
GB
Hi!

I have a combo box that when clicked shows the code and description of 10 items. However, once a selection is made i need only the code NOT the description to populate the box... does anyone know how i can do this??

ColdFusion Code:

<td>Risk Code:</td>
<td><select type=&quot;text&quot; name=&quot;riskCode&quot;>
<option value=&quot;&quot; SELECTED>-- Select --</option>
<cfoutput query=&quot;riskCodeQuery&quot;>
<option value=&quot;#RISK_CODE#&quot;>#RISK_CODE# - #RISK_CODE_DESC#
</cfoutput>
</select>
</td>

Thanks

Julie
 
I think you've got it already. The value of the formfield _IS_ the code. The formfield is called &quot;riskCode&quot; and its value is the #RISK_CODE# that is associated with the selected option.

Please note: the <SELECT> tag does not have an attribute called &quot;type&quot; . It will be ignored by most browsers, but you should just leave it out. So, your CF code would look like this:

<td>Risk Code:</td>
<td>
<select name=&quot;riskCode&quot;>
<option value=&quot;&quot; SELECTED>-- Select --</option>
<cfoutput query=&quot;riskCodeQuery&quot;>
<option value=&quot;#RISK_CODE#&quot;>#RISK_CODE# - #RISK_CODE_DESC#</option>
</cfoutput>
</select>
</td>

Also, if there is any possibility that riskCodeQuery.RISK_CODE would every be a zero-length string, you might want to give the first element some value such as &quot;unselected&quot; so that you can positively determine that no element was selected.
 
I get the same thing with that,

once I select something, both the code and the description are inserted into the drop down box.
i.e #RISK_CODE# - #RISK_CODE_DESC#
which is fine for the values in the drop down, however when a selection is made i just want #RISK_CODE# to fil the drop down box without the description.

what else should i try

cheers
jules
 
Oh! Let me re-phrase to see if I understand. When the user selects something from the select list, you want the VALUE of the selected to replace the text that is seen in the select list?

You say &quot;once I select something, both the code and the description are inserted into the drop down box&quot;. I don't understand how that's possible. When a user selects something, nothing else happens until the form is submitted (unless you have some JavaScript that gets invoked upon selection. Could you post a working version of your code? Not the whole thing, but just post a stripped-down version that illustrates the problem. Please include the containing <form> tags.

On second thought, maybe you are misunderstanding how the whole thing works. When you select something, nothing is inserted into the select list, BUT the element that is selected DOES appear in the select list box. When the form is submitted, the VALUE of the element that was selected is passed to the processing template as a form variable.

Let me know if this isn't clear.
 
I think my wording was VERY confusing!

<td>Risk Code:</td>
<td>
<select name=&quot;riskCode&quot;>
<option value=&quot;&quot; SELECTED>-- Select --</option>
<cfoutput query=&quot;riskCodeQuery&quot;>
<option value=&quot;#RISK_CODE#&quot;>#RISK_CODE# - #RISK_CODE_DESC#</option>
</cfoutput>
</select>
</td>

When i select an option both #RISK_CODE# and #RISK_CODE_DESC# are the elements that appear in the list box, I only want the #RISK_CODE# to appear in the list box! I don't suppose that can be done?

Jules

 
Try this and see if it works:

<form name=&quot;formname&quot;>
<select name=&quot;test&quot; onChange=&quot;document.formname.test.options[selectedIndex].text = document.formname.test.options[selectedIndex].value;&quot;>
<option value=0 SELECTED>--- Select Value ---
<option value=&quot;3&quot;>3 - Test Value
<option value=&quot;4&quot;>4 - Other Test Value
</select>
</form>

If I understood you correctly, you wanted (in this example), when the user selects &quot;3 - Test Value&quot;, the label of that option should change to JUST '3'. Right?

If so, this should work.

Hope it does!

MG
 
That's just what i wanted, but once i've selected and then i go and try to select something else, the code that i selected first hasnt got a corresponding description.

E.g. the list looks like this

js - javascript
asp - activeserverpage

when i select javascript the code i need goes into the box
js

when i click on the drop down box again the list looks like this

js
asp - asctiveservepage

how do i get the description back again?

cheers
Jules
 
You can't have it both ways. There are two &quot;lists&quot; associated with a select list: the list that is displayed and that the user sees, and the list of values associated with the elements of the list. In order to accomodate your requirement, the displayed text (the text that appears in the select list) had to be changed upon selection.
 
I actually think that can be done, but its a javascript nightmare. Or I might be wrong and it might not be able to be done at all. You might want to ask in the Javascript forum to see if anyone knows. I'm not even close to knowing enough to be able to help you.
 
I could be done You see, the code that was suggested obliterates the string &quot;#RISK_CODE# - #RISK_CODE_DESC#&quot; (when it's selected) and changes it to be just the risk code. To change the string back would mean that you would have had to save the string before it was wiped out, then restore the string, then save the new string, then obliterate the new string. Think hard as to whether you REALLY need the displayed string to change upon selection. If you still want that behavior, then this is an EXCELLENT time to say &quot;I leave that as an exercise for the student&quot;. It's time that you bought yourself a book on JavaScript and started using it. Now that we've pointed you in the right direction, it's time for you to dosome of the work. It's very simple to do if you know how to program (I just described how to do it).

Cheers and good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top