Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to preserve whitespace - now with javascript

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how you preserve whitespace in a form's <option>s in a select list?

I see how to do it in a text area, but not in a select list. I did try whitespace re, which didn't work.

[edited to disable smilies]

[ July 18, 2007: Message edited by: Jeanne Boyarsky ]
[ July 18, 2007: Message edited by: Jeanne Boyarsky ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be a little more explicit about what you are trying to accomplish?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. Suppose I have the following code.



I want the browser to display the whitespace in my entry. In particular, I am trying to align columns of data between different select options.

As in, the following - where the space alignment means something.


[edited to fix alignment in example]
[ July 18, 2007: Message edited by: Jeanne Boyarsky ]
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that only the non-braking space is available here.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amazing what the forum search turns up: http://www.coderanch.com/t/119503/HTML-JavaScript/spaces-select-option-tag-dropdown



Eric
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan,
I don't follow. I tried using &nbsp; The browser displayed it as &nbsp;, not as a space.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric,
Yes, but you have to know what to search for . I didn't hit the right keywords. Thanks!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spoke too soon. That works when I can hard code it in the HTML. However I need to do it through JavaScript "new Option()" code. That still displays it as &#160;
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

The following worked well in IE6 and FireFox 1.0:



Regards,
Dan
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well with JavaScript use: \xA0

Eric
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both so much for the help. I just tried a dummy page and it works!

Dan: I need to look at my test at work. At home, &bsp;, &#160; and \xA0 all work from JavaScript. This implies that there is a problem with my test. I must be making things more complicated than they need to be. It's the same browser (Firefox.) Interestingly in IE 7, just leaving the blank space works.

And for future reference to myself, &#xa0; is unicode.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And to close this out:
At work, the Unicode one correctly displays the space while the &#160; and &nbsp; do not. I'm not sure why, but I'm glad I have something that works. It must have something to do the with the way I'm calling the JavaScript as my "home" example works correctly on my work machine too.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

You said -


And for future reference to myself, &#xa0; is unicode.


&#160; and &#xa0; are equivalent. &#160; is a decimal character reference while &#xa0; is the hexadecimal character reference.

"XML in a nutshell" says the following on page 424 �


For instance, the nonbreaking space is Unicode character 160 (decimal). Therefore, you can insert it in your document as either &#160; or &#xA0;. If you really want to type it as &nbsp;, you can define this entity reference in your DTD. Doing so requires you to use a character reference:

<!ENTITY nbsp "&#160;">


Regards,
Dan
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan,
Thank you. That is good to know.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic