Jump to content

how do i start a newline and add space in javascript?


RyanSchurton

Recommended Posts

var donation = new Array(4);  for (var i = 0; i < donation.length; ++ i) {	 donation [i] = new Array(4)} 	donation [0][0] = "#111";	donation [0][1] = "Jane";	donation [0][2] = "Doe";	donation [0][3] = "$100.00";	donation [1][0] = "#222";donation [1][1] = "John";donation [1][2] = "Doe";donation [1][3] = "$200.00";	donation [2][0] = "#333";donation [2][1] = "Joe";donation [2][2] = "Smith";donation [2][3] = "$300.00";document.write(donation [0][0]);document.write(donation [0][1]);document.write(donation [0][2]);document.write(donation [0][3]);document.write(donation [1][0]);document.write(donation [1][1]);document.write(donation [1][2]);document.write(donation [1][3]);document.write(donation [2][0]);document.write(donation [2][1]);document.write(donation [2][2]);document.write(donation [2][3]);

my output for my code is: #111JaneDoe$100.00#222JohnDoe$200.00#333JoeSmith$300.00 but i need to to look like this: #111 Jane Doe $100.00#222 John Doe $200.00#333 Joe Smith $300.00 with more space between the #111, Jane, Doe and 100.00.

Edited by RyanSchurton
Link to comment
Share on other sites

I hesittate to support the use of document.write -- but I'll assume your reasons make sense. 1. Try putting your text inside <pre></pre> tags. that should preserve the formatting. 2. Use \t and \n (in quotes) for tabs and newlines.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Well, I can. I sort of hate to, but I tested this and it "works." I suggest doing a View Source before and after you click the text to execute the function.

<!DOCTYPE html><html>    <head>        <script type="text/javascript">            function writeMe() {                var s = "<pre>hi";                s += "\n";                s += "John";                s += "\t\t";                s += "Smith </pre>";                document.write (s);                document.close();            }        </script>    </head>    <body>        <p onclick="writeMe()">Click me</p>    </body></html>

Edited by Deirdre's Dad
Link to comment
Share on other sites

Above one is also well & good.But this also is going to work & i've checked it:-donation [0 ][ 0] = "#111 " ;donation [ 0 ][1 ] = " Jane " ;donation [ 0 ][2 ] = " Doe " ;donation [ 0 ][3 ] = " $100.00" ;donation [ 1 ][0 ] = "<br>"+"#222 ";donation [1 ][ 1] = " John " ;donation [1 ][ 2] = " Doe " ;donation [1 ][ 3] = " $200.00" ;donation [ 2 ][0 ] = "<br>"+"#333 ";donation [2 ][ 1] = " Joe " ;donation [2 ][ 2] = " Smith " ;donation [2 ][ 3] = " $300.00";left all same.I've added some "spaces" & <br>.For adding a newline...just go for break.donation[2][0]="<br>"+"#333 ";& add space under " " (double quotes) whereever you want it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...