Printing Multiple Lines In a Window

Documentation warns against document.writeln(), but InnerHTML doesn’t do what I need. InnerHTML erases each previous line and starts at “home”. If you have 50 lines of data, you lose 49 lines. This despite all the
or \n you insert. The workaround is to concatenate all in a single string. This is fine for 10-20 lines, but risky for 50-5,000 lines.

BACKGROUND: I had 30 years in IT, at the Pentagon, Ft. Leavenworth, and, after retirement, Wal-Mart Information Systems. I’ve done dBase III Plus, Informix, Oracle, C, Visual Basic, and Unix batch file dialects. Programming is fun, no matter what the language.

Old timey PCs had QBASIC. You could do various quick and dirty things with that, at need. Modern Microsoft OSs have done away with that. If you need to program, but don’t want a compiler ($$$), all you have, now, is batch file, and Javascript. I’m learning Javascript.

I need help printing to a window, so it doesn’t overwrite previous. If document.writeln() is dangerous, what should I use?

We might need a little more context about what you are trying to do.

You can do string concatenation so you add to what is already inside an element.

<p>Content</p>
// or innerText or textContent
document.querySelector('p').innerHTML += ' More Content'

You can use append, appendChild, or one of the “insertAdjacent” methods. It also depends on if you are creating nodes/element to be inserted or just HTML strings.

The latest version of the freeCodeCamp curriculum teaches DOM manipulation.

Basically, I’m asking for two or three integers input, doing a series of calculations, and outputting the results. There are between six and ten results for square cut gears, and perhaps 15 for cutting miter gears. The formulae are from Engineers Handbook. I’m not nesting web pages, or offering a plethora of choices, with radio buttons and checkboxes. Just simple calculations to aid in hobbyist machining.

I was more referring to how you are/need to put the data on the page.

But again, you do not need to overwrite the page/element content. You can concatenate or append the new content to the old.

Example:

Tooth diametric pitch: 18
Outside Diameter: 3.7222
Number of teeth requested: 65
Number of holes in dividing head circle: 29
Number of holes selected per tooth: 14
Number of whole turns: 0
Error rate per tooth: 0.00
Cumulative error rate: 0.00
Error rate makes project unworkable: False
and whatever other fields may be relevant.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.