aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes how to preserve whitespace - now with javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to preserve whitespace - now with javascript" Watch "how to preserve whitespace - now with javascript" New topic
Author

how to preserve whitespace - now with javascript

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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 ]

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Can you be a little more explicit about what you are trying to accomplish?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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

Joined: Jul 09, 2001
Posts: 1164
It seems that only the non-braking space is available here.


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Amazing what the forum search turns up: http://www.coderanch.com/t/119503/HTML-JavaScript/spaces-select-option-tag-dropdown



Eric
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Dan,
I don't follow. I tried using &nbsp; The browser displayed it as &nbsp;, not as a space.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Eric,
Yes, but you have to know what to search for . I didn't hit the right keywords. Thanks!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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

Joined: Jul 09, 2001
Posts: 1164
Jeanne,

The following worked well in IE6 and FireFox 1.0:



Regards,
Dan
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Well with JavaScript use: \xA0

Eric
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

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

Joined: Jul 09, 2001
Posts: 1164
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Dan,
Thank you. That is good to know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to preserve whitespace - now with javascript
 
Similar Threads
cste exam
Thanksgiving Seals
how is [Company],bangalore
how is [Company],[Place],[City]
action types