To add a line-break in the text content, you need to use
'\n'
:
var result = strText + '\n' + strText1;
However, most HTML elements ignore line-breaks and other spaces within their content.
You can either use
a <pre>
element[
^]:
<pre id="spanResult"></pre>
Demo[
^]
or you can set
the white-space
CSS property[
^] to
pre-line
:
<style>
#spanResult {
white-space: pre-line;
}
</style>
Demo[
^]
Complete example:
<!DOCTYPE html>
<html>
<head>
<script>
function testVariable() {
var strText = document.getElementById("textone").value;
var strText1 = document.getElementById("textTWO").value;
var result = strText + '\n' + strText1;
document.getElementById('spanResult').textContent = result;
}
</script>
<style>
#spanResult {
white-space: pre-line;
}
</style>
</head>
<body>
<input type="text" id="textone" value="• Name/ Title :" />
<br>
<input type="text" id="textTWO" value="• Phone #: " />
<br><br>
<button onclick="testVariable()">Submit</button> <br />
<span id="spanResult"></span>
</body>
</html>