I currently have a select which shows options as
<option>{{ tag.name }} ({{ tag.count }})</option>
However, I would like that when the user selects the option, in the selected options, only the name is visible and not the last part. Think of how stack* shows the tag count but hides it when you select it.
Ideas? Thanks.
Edit: Sorry for not being clear. In chosen, when you select an option, a textbox fills up with the selected data. I want that text to be modified, not the one on the <select>!
EDIT: For your edit, if the option elements have a
valueattribute set to the text you want to use try:Demo: http://jsfiddle.net/CdKGT/2/
Or if you can’t use the
valueattribute for some reason and want to extract the text from what is displayed:Demo: http://jsfiddle.net/CdKGT/3/
Obviously you’d use an id or class to identify the select and input rather than just
$("select")and$("input"), but you get the idea.MY ORIGINAL ANSWER (for my interpretation of your original question):
You could do something like this:
And then:
Demo: http://jsfiddle.net/CdKGT/1/
(Obviously you can optimise the function a bit by caching the jQuery objects and so forth, but I kept it simple for proof of concept.)