Posts [ 12 ]

Topic: Selected item in a select box

I suspect this is a browser issue rather than a rails issue. I'm creating a select tag in rails and it's correctly putting

selected="selected"

by the appropriate option. However when I view the page (in Firefox at the moment - haven't got any other browsers installed on this machine at present) the item showing in the select box is always the top item and not the one with the selected code. Any idea why? This is really infuriating!

Re: Selected item in a select box

I've actually changed the code to use a multi-select box now! But no, only one menu item had the selected attribute. I may have been using the select box elsewhere but it's hometime now so I'll check tomorrow.

That sets the correct selected="selected", but Firefox does not show the two selected items. IE6/7, Opera9 and Netscape8 do it.

So you are right, it's more a browser issue :-) having browser compatibility issues can be a pain in the a...

EDIT: just adjusted the code. Made 2 little mistakes as I wrote it out of my head. First, to select multiple items you need an array ("some_name[]", not just "some_name"). Secondly, since this build upon a regular select box, you need to assign a class to it that defines the width and height - otherwise it'll just be displayed as regular select box with 1 single line.

Re: Selected item in a select box

I use that quite a lot - options_for_select is nicely explained in the api. One could probably use collection_select instead, but I have not tried that yet.

And like I said, the selected highlighting works in most browsers, but unfortunately not Firefox. From a professional perspective, however, it's fine as long as it works in IE6 and 7 as most of the users still use IE6. I can hear the voices now shouting about browser intercompatibility, but the majority of our clients just know enough to turn their PC on - people working in the field probably know what I am talking about

Re: Selected item in a select box

Weird. It may have something to do with the HTTP headers which are sent back. But I don't see how that would affect the select box.

Try validating the page to make sure there's no obvious problems (tags left open, etc.). But even then I imagine it would behave the same whether you paste the HTML directly or it is returned from a Rails site.