Forum Discussion
How to capture a line break while printing a text area
Hello there!
I am printing a text area using Javascript. However, I am unable to capture the line break in the text area.
I've included the Javascript here for you to refer to.
console.clear();
var questionTitleVar = 'A6_Name';
var question1 = 'A6_Q1_TextEntry';
var response1 = 'A6_TextEntry_1';
var styles = `
#printHelper, #printHelperTitle {
display: none;
}
@media print {
html {
height: auto !important;
}
body * {
display: none;
}
#printHelper, #printHelperTitle {
display: block;
overflow: visible;
white-space: pre;
white-space: pre-wrap;
}
#printHelperTitle {
font-size: 24px;
}
#printHelper, #printHelperResponse {
display: block;
overflow: visible;
white-space: pre;
white-space: pre-wrap;
}
#printHelperResponse {
font-size: 12px;
}
#printHelper, #printHelperQuestion {
display: block;
overflow: visible;
white-space: pre;
white-space: pre-wrap;
}
#printHelperQuestion {
font-size: 16px;
}
}
`;
var stylesheet = document.createElement('style');
stylesheet.nodeType = 'text/css';
stylesheet.innerText = styles;
document.head.appendChild(stylesheet);
var player = GetPlayer();
var screenTitle = player.GetVar(questionTitleVar);
var screenTitleEl = document.createElement('h1');
screenTitleEl.id = 'printHelperTitle';
screenTitleEl.innerText = screenTitle;
document.body.appendChild(screenTitleEl);
var Q1Title = player.GetVar(question1);
var Q1TitleEl = document.createElement('h3');
Q1TitleEl.id = 'printHelperQuestion';
Q1TitleEl.innerText = Q1Title;
document.body.appendChild(Q1TitleEl);
var Q1Response = player.GetVar(response1);
var Q1ResponseEl = document.createElement('h5');
Q1ResponseEl.id = 'printHelperResponse';
Q1ResponseEl.innerText = Q1Response;
document.body.appendChild(Q1ResponseEl);
window.print();
screenTitleEl.remove();
Q1TitleEl.remove();
Q1ResponseEl.remove();
console.clear();