Click to See Complete Forum and Search --> : Displaying blank spaces & javascript.
PatrickMartz
01-13-2003, 05:58 PM
Ok, I have just encountered a rather odd issue with javascript. I have some text that I want to be dynamic and it will change when users select various options on the web page. I also want said dynamic text to include EXTRA whitespace. (i.e. "blah blah blah blah blah blah"). Now, if I attempt to set the text in my javascript code, in IE it works just fine and the spaces show up. However, in Netscape 6.x and above, it eats up all the extra whitespace.
Thus the next thing I tried was inserting "& n b s p ;" or "& # 1 6 0 ;" (minus the spaces) into the javascript string. Much to my surprise, when displayed, it came out with "& n b s p ;" and "& # 1 6 0 ;". It did not replace the codes with spaces. Does anyone know of ANY way to get netscape to dynamically display white space this way? I can't just add spaces and I can't use the codes. Where does that leave me??
TIA.
PatrickMartz
01-13-2003, 06:43 PM
In this particular case, I am putting the data into an OPTION tag for a SELECT. For example, I do something like:
var str = "blah blah blah";
str = str + "& nbsp;& nbsp;& nbsp;& nbsp;"
str = str + "endblah endblah endblah";
window.document.form1.MyList.options[1].text = str;
Then what I see in the select field is "blah blah blah& nbsp;& nbsp;& nbsp;& nbsp;endblah endblah endblah". Again both minus all the spaces. Whenever I enter them without spacing in here they show up as empty spaces. :)
PatrickMartz
01-13-2003, 07:56 PM
Doh! Ok that worked in IE. But then in netscape it didnt take the unescape at all. Or so it appears. How frustrating! Since netscape was the problem to begin with. When I try using unescape in netscape it just (once again) eats up all the white space. Oh well. Thanks for trying and if anything else occurs to you, I'd appreciate a line. :)
PatrickMartz
01-13-2003, 08:02 PM
Wait, nevermind. I am sorry I made it work after all in netscape as well. Thank you SO much for your help. :)
Webskater
01-14-2003, 04:59 AM
Please oost exactly what you write in the javascript code to get a space to appear. This is driving me nuts. I am using \t which puts a tab in which seems to more or less take up the space of a space (as it were) but I would love to know exactly what you should put after the "\" to write a space. Thanks.
PatrickMartz
01-14-2003, 10:44 AM
Ok. Well here is the problem. As Dave mentioned earlier, when setting a string programmatically in javascript, any special characters such as & nbsp; etc. do not get interpreted so they come out exactly as typed in!
So, what I did was when creating the string, any set of extra blank spaces that I wanted to appear (beyond just one blank space), I replaced with %A0 which is the hex code for the nonbreaking space. Then call unescape on that string to translate those hex codes into the nonbreaking spaces. The reason I thought it wasnt working in netscape initially is because I was using the code for a REGULAR space, not the non-breaking one.
Thus an example of my code might look something like:
var str = "blah blah blah";
str = str + "%A0%A0%A0%A0";
str = str + "endblah endblah endblah";
window.document.form1.MyList.options[1].text = unescape(str);
And voila. It comes out with extra spaces. :) Again, Thanks for the help.