PDA

View Full Version : How to add a space in javascript coding


tpeck
03-14-2003, 10:31 AM
Hi all,

I would like to know how to add a space in javascript that "sticks"and doesn't resolve to nothing.

Here is my code:

obj_table_time.innerHTML = " " + day + " "+date.getDate()+" " + maand +" < " +date.getHours() + ":" + minutes +":" + seconds +" >";

It doesn't really matter what the code is trying to do, I just want the first space to register as a REAL space. At present it just gets wiped out.

Interestingly, all spaces within quotation marks seem to get wiped out UNLESS there is a character within them. So what are the spaces there for anyway? What is going on? Or rather, what makes a HARD space?

Many thanks,

Terry

Tommi
03-14-2003, 12:13 PM
Try innerText instead of innerHTML or use the special tag/code (whatever) & nbsp; (don't forget to remove the gap beween & and nbsp; !)

maybe that works...

tpeck
03-14-2003, 11:20 PM
Hi Tommi,

innerText works!

If you look at the page http://www.aapress.com.au the space before the day of the week top left comes courtesy of yourself!

Many thanks,

Terry

cheesebagpipe
03-14-2003, 11:46 PM
If you're using .innerText, might want to add this:

<script type="text/javascript">

if (!document.all) alert('You must load this in Internet Explorer!');

</script>

tpeck
03-15-2003, 12:13 AM
Yeah, right, it doesn't work in Netscape...

This works in IE:

obj_table_time.innerHTML = "&nbsp" + day + etc.

... but not in Netscape.

This works in IE:

obj_table_time.innerHTML = '&nbsp' + day + etc.

... but not in Netscape.

Is there anything that provides a hard space and works in both browsers?

same old...

Terry

tpeck
03-15-2003, 12:17 AM
Oops! forgot to put the display space between the & and the nbsp;

This works in IE:

obj_table_time.innerHTML = "& nbsp" + day + etc.

... but not in Netscape.

This works in IE:

obj_table_time.innerHTML = '& nbsp' + day + etc.

... but not in Netscape.

(without the spaces between the & and nbsp...

Terry

cheesebagpipe
03-15-2003, 12:21 AM
Did you try:

&amp;nbsp;

???

tpeck
03-15-2003, 12:26 AM
U beaut!

It works in both - I must not be so sloppy...

Thanks Tommi, thanks cheesebagpipe.

Cheers!

Terry