RyanSchurton Posted January 26, 2013 Share Posted January 26, 2013 (edited) 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 January 26, 2013 by RyanSchurton Link to comment Share on other sites More sharing options...
jeffman Posted January 26, 2013 Share Posted January 26, 2013 (edited) 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 January 26, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
RyanSchurton Posted January 26, 2013 Author Share Posted January 26, 2013 Could you show me where i would place the <pre></pre> \t and \n tags when i try it, my text no longer shows in browser. Link to comment Share on other sites More sharing options...
jeffman Posted January 26, 2013 Share Posted January 26, 2013 (edited) 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 January 26, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
anuj2luv Posted January 26, 2013 Share Posted January 26, 2013 (edited) :-) Edited January 26, 2013 by anuj2luv Link to comment Share on other sites More sharing options...
anuj2luv Posted January 26, 2013 Share Posted January 26, 2013 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 More sharing options...
jeffman Posted January 26, 2013 Share Posted January 26, 2013 An alternative is to put the data in a table. The would give you neat rows and columns to work with. The cell borders are optional and can be styled. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now