Forum Moderators: open

Message Too Old, No Replies

JavaScript \t is there a space to?

tab is to big

         

mossimo

12:39 am on Oct 13, 2003 (gmt 0)

10+ Year Member



With JavaScript we have \t = Tab
But is there one for a space becuse tab is to big?

MonkeeSage

1:37 am on Oct 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not that I know of, except in the regular expressions context (in which case it is '\s'). If you just want a literal space, you can escape it like any other char...'This is a test\ string'...or you could use the \uXXXX unicode escape and use the code for a normal space, but I'm not sure what that is offhand...for a non-breaking-space it is \u00A0 if that helps any.

Jordan

korkus2000

1:56 am on Oct 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where will the outputted string going to be?

mossimo

4:16 am on Oct 14, 2003 (gmt 0)

10+ Year Member



I am am formating html code in a client side JavaScript editer html editor.
When in code view mode the code is pulled from a hiddin <div> and put into a textarea.

\t \n ect... is the only method I have to format the visual areance of the code in the editor

I'm trying to get this:


<table>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>

Insted of this:

<table>
<tr><td></td> </tr>
<tr><td></td>
</tr></table>

MonkeeSage

4:43 am on Oct 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I'm not mistaken when you change the textarea .value property you can use literal spaces, e.g.,

...
ta.value += " " + somevar;
...

Jordan

[edit:]

To expand on that a bit...

... 
<div id="hd">
This is some text and
&lt;tags&gt; and such to be
put into the textarea!
</div>

<textarea id="ta"></textarea>

<script type="text/javascript">
<!--
var hd = document.getElementById("hd");
var ta = document.getElementById("ta");
var val = hd.innerHTML;
val = val.split(/\r?\n/);
for (var j = 0; j < val.length; j++) {
ta.value += " " + val[j] + "\n";
}
//-->
</script>
...

Works for me...

[/edit]