Embedding Non-Breakable Spaces into Strings -- How?

H

Hal Vaughan

I have a list of variables and values (merge fields for a merge program) and
I want to put them in a list in a <SELECT> object. I'd like them to be
lined up, with an "=" midway between the field and the value. I was going
to fill the space between with spaces, but I noticed a number of spaces are
condensed to one (like in all other parts of HTML). I tried filling it
with non-breakable spaces, like this:

var line = "MyMergeField&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;MyValue";

And the non-breakable space is not interpreted -- it is entered into the
string literally. Is there a way to enter this character into a string?
Perhaps by hex value? Or is there some other way I can create spacing to
line up the equals signs so it looks good to users?

Thanks!

Hal
 
F

Fox

Hal said:
I have a list of variables and values (merge fields for a merge program) and
I want to put them in a list in a <SELECT> object. I'd like them to be
lined up, with an "=" midway between the field and the value. I was going
to fill the space between with spaces, but I noticed a number of spaces are
condensed to one (like in all other parts of HTML). I tried filling it
with non-breakable spaces, like this:

var line = "MyMergeField&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;MyValue";

var nbsp = String.fromCharCode(160);

line = nbsp + nbsp + MyValue;


And the non-breakable space is not interpreted -- it is entered into the
string literally. Is there a way to enter this character into a string?
Perhaps by hex value? Or is there some other way I can create spacing to
line up the equals signs so it looks good to users?

different fonts have differing spacing characteristics (no telling what
the user has set up) -- you might want to "force" a monospace font for
the style of the select.

I think Andale Mono will work, as will Courier New, but always fall back
on the generic "monospace" to make sure.
 
H

Hal Vaughan

Fox said:
var nbsp = String.fromCharCode(160);

line = nbsp + nbsp + MyValue;

Thanks -- exactly what I needed!
different fonts have differing spacing characteristics (no telling what
the user has set up) -- you might want to "force" a monospace font for
the style of the select.

I think Andale Mono will work, as will Courier New, but always fall back
on the generic "monospace" to make sure.

I already set that up, since the rest of my page is in Arial.


Thanks for the help!

Hal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top