dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to line break between document.write entries?

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    How to line break between document.write entries?

    Hello,

    I'm using the script below to list files stored locally on a webpage (I'm developing a small application that is to be loaded from a CD-ROM). It's been done in HTML as per my company's request.

    Essentially, this script works and successfully populates a list of files stored in the folder given by its parameter. However, I wanted a line break between the entries (hence \n) but it doesn't seem to work. I have tried the <pre> tag before and after the div this is printed to, as well as around the script - but it doesn't seem to have any effect. All I get is spaces.

    Do you have any ideas?

    Thanks

    P.S. I had an idea for an alternate solution, if it is an option: perhaps a better way would be to use an unordered list and have a script that adds list items to it? I can't seem to find this anywhere online either.

    <SCRIPT>

    function listFiles(thefolder)
    {

    var fso = new ActiveXObject("Scripting.FileSystemObject");
    if(fso.folderExists(thefolder))

    {
    bbb=fso.GetFolder(thefolder)
    aaa=""
    oFileColl = new Enumerator(bbb.files);
    abc = new Array();
    i=0

    document.all['listing'].innerHTML = "";

    for (; !oFileColl.atEnd(); oFileColl.moveNext())
    {
    tempp = new String(oFileColl.item());
    name = new String(fso.GetFileName(tempp));
    //Tempp = file location.
    if((tempp.indexOf(".pdf")!=-1)||(tempp.indexOf(".dwg")!=-1))
    {
    //document.all['listing'].innerHTML += (name.link(tempp)+"\n\n");

    var container = document.getElementById('myList');
    var new_element = document.createElement('li');
    new_element.innerHTML = (name.link(tempp)+"\n");
    container.insertAfter(new_element, container.firstChild);


    abc[i]=tempp
    i++
    aaa+=tempp+"\n"
    }
    }
    }
    }
    </SCRIPT>

  2. #2
    Join Date
    Apr 2010
    Location
    Cocoa Beach, FL
    Posts
    41
    I have not validated this yet, but I have similar javascripts on my web applications that set the text content of a div, using the innerHTML property. Usually you have to use html tags to format the text the way that you want. Using document.write is a javascript feature but it is writing text to the HTML scope so you should use HTML in the text you are writing, try writing the line break tag <br> at the end of your sentences and that should help. Also you can enclose your text content in the <p> tag to seperate it from other text content.

    Here is an example that should work, writes a bold font sentence to the browser and ends the sentence with a newline using HTML.

    document.write("<b>This is a test sentence</b><BR>");

    Michael G. Workman
    michael.g.workman@gmail.com

  3. #3
    Join Date
    Jul 2011
    Posts
    2
    Thanks for the quick reply Michael, I think I tried all of the difficult ways and didn't think that would work. (That did.)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles