gerkintrigg Posted August 19, 2012 Share Posted August 19, 2012 I'm trying to make a javascript calculator to work out if something is viable, but there's an issue with the formatting. I want to output a line break like I can with PHP, but Javascript doesn't want me to do it. I've tried \n and <br\/> but neither work. Please help. Here's my code: <script> function ViabilityCheck(){ // define the variables: var print_quote = document.getElementById('print_quote').value; var handling = document.getElementById('handling').value; var postage = document.getElementById('postage').value; var discount = document.getElementById('discount').value; var rrp = document.getElementById('rrp').value; var output_div_field = document.getElementById('output_div_field').value; // now work out the viabilty and put that out as a variable: var OurCut = ((rrp/100)*(100-discount)); var output_div = document.getElementById('output_div'); while( output_div.firstChild ) { output_div.removeChild( output_div.firstChild ); } var OVOurCut='Turnover Per Book: ?'+OurCut.toFixed(2); var OVGrossProfit='Turnover less the printing cost Per Book: ?'+(OurCut.toFixed(2)-print_quote); output_div.appendChild( document.createTextNode(OVOurCut+'<br\/>'+OVGrossProfit)); } </script> Link to comment https://forums.phpfreaks.com/topic/267302-outputting-line-breaks-as-line-breaks/ Share on other sites More sharing options...
requinix Posted August 19, 2012 Share Posted August 19, 2012 You're creating text nodes. Text nodes cannot contain HTML - that's basically their entire point. Add the first text node, add a new node, then add the other text node. Link to comment https://forums.phpfreaks.com/topic/267302-outputting-line-breaks-as-line-breaks/#findComment-1370640 Share on other sites More sharing options...
jardrake Posted August 19, 2012 Share Posted August 19, 2012 If your outputting to a text field, neither of those will work. However, if you are outputting to a textarea the \n would work. You might want to create 2 different divs if you want to use the br. Link to comment https://forums.phpfreaks.com/topic/267302-outputting-line-breaks-as-line-breaks/#findComment-1370724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.