views:

15

answers:

1

I have dropdown list (HTML select element) which simply contains a heap of dollar amounts. E.g.

$50,000

$100,000

$150,000

$200,000

and so on..

An example of one of the option elements inside it would be:

<option value="150000">$150,000</option>

I want the user to be able to start typing in 1..5..0.. and get it to auto-jump down to the $150,000 item - this works fine natively in most browsers if I didn't have any $ symbol in my innerhtml. But because all of my innerhtml descriptions are prefixed with a $ sign, the keyboard shortcuts are all identical, so effectively useless.

I'm assuming there is no simple way in raw HTML to specify that the keyboard shortcuts should be obtained from the corresponding value attribute, rather than the innerhtml text?

So what would be the cleanest jquery snippet to achieve this?

+1  A: 

If at all possible, I would simply put the $ in front of the drop down menu. That would be the least painful way.

If that is not an option, you could consider using a background-image containing a $ sign for each option:

select.dollar option { background-image: url(...); 
                       background-position: left center; 
                       background-repeat: no-repeat;
                       padding-left: 20px;
                      }

browser support for that is very, very flaky, though - it would work probably only in the very newest version of each family. It may not work in IE at all, I don't have an overview handy. Also, this way is not good for future internationalization.

Other than that, I think you would have to resort to a JavaScript based custom drop-down.

Pekka
Thanks. Yeah I agree, the background-image method is very flaky and not desirable. I would want something as simple and robust/clean as possible, preferably not using graphics. I thought of the $ sign before the actual dropdown itself idea and it probably is the best one I can think of, but unfortunately the appearance suffers.
Aaron
Funnily enough, I think I am going to end up going with a slight variation of your background image idea. I actually have a flat background image behind my whole form, to make the fields appear kind of modern/3D etc. So rather than putting a background $ symbol with CSS behind each option element, I'll just add a one-off on the background and it will work because my select doesn't have a border, so it will hopefully look seemless. Thanks for the idea. I've removed the $ symbols out of the option elements anyway and now at least the keyboard shortcuts work nicely.. I'll give you a point.
Aaron