Giorgio
Giorgio

Reputation: 1970

Select an option containing accents with jQuery

I have a select element. Some option may contain accents, so to display them properly I've converted them to HTML entities.

<select id="someid">
    <option>Select...</option>
    <option>Option one</option>
    <option>Option tw&ograve;</option>
</select>

My goal is to select one of the given options with jQuery. If the chosen option doesn't contain accents, everything works fine.

$("#someid").val("Option one"); // works

But when I try to select an option containing accents, it fails.

$("#someid").val("Option tw&ograve;"); // fails

Here's a fiddle showing the problem.
How can I select an option containing accents?

Upvotes: 3

Views: 445

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337656

You need to use the actual character in the value in jQuery:

$("#someid").val("Option twò"); 

Example fiddle

Upvotes: 3

Related Questions