File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes spaces in select/option tag dropdown menu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "spaces in select/option tag dropdown menu " Watch "spaces in select/option tag dropdown menu " New topic
Author

spaces in select/option tag dropdown menu

Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Hi All,

I have a dropdown menu which is populated with a value 'NEW YORK SUMMARY'.
Please note that there are 2 spaces after NEW.

When dropdown menu is displayed in browser , I see 'NEW YORK SUMMARY'. ,i.e one space removed.

because of this my validations further are failing. Can somebody advise on this ?

Thanks
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
Have you tried with NEW  YORK SUMMARY ?
Good Luck!


2B || !2B
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Issue #1: Why would your validations depend upon the display text of a select option? That's pretty fragile. I'd revisit this design.

Issue #2: HTML collpases whitespace. Perhaps you could try   character entitites?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Yes , i tried with NEW YORK SUMMARY with 2 spaces , it replaces multiple spaces with one space.


Issue #1: Why would your validations depend upon the display text of a select option? That's pretty fragile. I'd revisit this design.


the populated dropdown , comes directly from database columns. so NEW YORK SUMMARY (with 2 spaces) comes directly from tables and I am checking my displayed value against the table value. If displayed value's space is preserved , It makes the validation straight forward.
Perhaps you could try   character entitites?


I don't know what kind of values I might recieve, so I can't use &npbsp
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
As Bibeault said it's not a good design to do exact text match. However if you don't have much control the design then you can use <pre> tag for each option element. This will preserve the text.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
When the browser renders the page it basically does a trim() method to wipe out all the extra crap in it unless it is in a pre.

To preserver the whitespace is a select you need to change the spaces over to its approproate entities. So that means you are going to have to do a replace method of the data returned from your database before it is displayed.



Eric
Pablo M�ller
Ranch Hand

Joined: Dec 12, 2006
Posts: 63
Hi again,
My last post had two   between NEW and YORK... But they were rendered as html... which it was
Sorry if it wasn't clear
Pablo
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

so NEW YORK SUMMARY (with 2 spaces) comes directly from tables and I am checking my displayed value against the table value


OK, I was apparently too subtle in my first post. Let me be clearer:

Relying upon the DISPLAY value of the option means that your design is BROKEN!

In other words:



is wrong wrong wrong!

Rather, do it correctly with:



and any spaces in the value will be preserved.
[ February 26, 2007: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: spaces in select/option tag dropdown menu