Link to home
Start Free TrialLog in
Avatar of phasevar
phasevar

asked on

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";

ASKER CERTIFIED SOLUTION
Avatar of smaccari
smaccari

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michel Plungjan
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>
No split?
Avatar of phasevar
phasevar

ASKER

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.
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.