Dynamically adding select options with html entities

It's fairly easy to add option elements to a select:

select = document.getElementById('MySelect');
opt = document.createElement('option');
opt.text = "New Option";
opt.value = "New Option";
try {
    select.add(opt, null);
} catch(ex) {
    select.add(opt);
}

But, how does one add elements which include html entities.  For instance:

opt.text = "£20";

phasevarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

smaccariCommented:
Try with innerHTML of the option:

<select id=myselect>
</select>
<script>
document.getElementById("myselect").options[1]=new Option("","");
document.getElementById("myselect").options[1].innerHTML ="&pound;20";
</script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michel PlungjanIT ExpertCommented:
ot this:
<select id="MySelect"></select>
<script>
pnd = unescape("%A3")
select = document.getElementById('MySelect');
opt = document.createElement('option');
opt.text = pnd+20;
opt.value = 20;
try {
    select.add(opt, null);
} catch(ex) {
    select.add(opt);
}
</script>
0
Michel PlungjanIT ExpertCommented:
No split?
0
phasevarAuthor Commented:
mplungjan, for some reason when I adapted your code to my application it didn't work in Firefox (or was it IE?  I can't remember now).   However, I just copied and pasted your example and it seems to work in both.  So maybe it was my error.  Sorry.  I guess it's too late to split.  I don't see the option.
0
Michel PlungjanIT ExpertCommented:
Yes it is too late. But that is ok. Just curious since my suggestion should work in the more standard way of creating options too.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.