<script>
var text ="abc xyz";
var value ="val";
var contrlObj = document.getElementById("sel");
var newOpt = new Option(text,value);
contrlObj.options[0] = newOpt;
</script>
No matter how many spaces I inserted, it always displayed as: abc xyz.
What I intend to to is to display it as abc xyz with multiple white spaces. I tried abc xyz, and it displayed as abc xyz.
After some experimentation I think that is not possible, at least in IE. Multiple spaces, however expressed, are collapsed into a single space. is, as you have found, rendered literally. Same for \u0020.
Using css can style the width of the select box, but cannot assist with adding intermediate spaces as required here.
Quizmaster: Name a character from any one of these four plays - Otheello, Macbeth, Coriolanus and Hamlet, who has a speaking part.
Contestant: Yorick.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
I find that you can change the existing value of a select list option text to include intermediate spaces (which seems a bit of a hack!):-
Code:
<select id = "myselect">
<option value = 0>Select a title...</option>
<option value = 1>Whatever</option>
</select>
<script type = "text/javascript">
function changeText() {
var otxt = document.getElementById("myselect").options[1].text;
var repText = " abc xyz";
document.getElementById("myselect").options[1].text = repText;
}
changeText();
</script>
As others have said, I am not sure why you would want to do this. I am sure we would all value enlightenment.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.