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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.