phasevar
asked on
Dynamically adding select options with html entities
It's fairly easy to add option elements to a select:
select = document.getElementById('M ySelect');
opt = document.createElement('op tion');
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";
select = document.getElementById('M
opt = document.createElement('op
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No split?
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.
<select id="MySelect"></select>
<script>
pnd = unescape("%A3")
select = document.getElementById('M
opt = document.createElement('op
opt.text = pnd+20;
opt.value = 20;
try {
select.add(opt, null);
} catch(ex) {
select.add(opt);
}
</script>