/    Sign up×
Community /Pin to ProfileBookmark

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.

[FONT=”Courier New”]<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)+”nn”);

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>[/FONT]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Michael_GJul 25.2011 — 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

[email][email protected][/email]
Copy linkTweet thisAlerts:
@respetenudillosauthorJul 25.2011 — Thanks for the quick reply Michael, I think I tried all of the difficult ways and didn't think that would work. (That did.) ?
×

Success!

Help @respetenudillos spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...