ionik Posted July 30, 2008 Share Posted July 30, 2008 Hello Everyone! Im having a bit of a problem with white space in Javascript ( and i cannot simply just remove it ) The problem I am experiencing is I have created a few various simple functions that insert text into a textarea, the problem I am experiencing is when I try to insert something that contains white space and a line break the code doesn't work giving me a error of a unterminated string. But it works fine if there are no line breaks or white space example works <img src="/csys/themes/I92/images/icons/quote.gif" onclick="insert_quote('[color=#FF0000][b]Yes[/b][/color] it was crazy beyond believe :drool:', 'i9.ioa^n1k')" border="0" alt="Quote this comment" title="Quote this comment" /> Example that doesn't work <img src="/csys/themes/I92/images/icons/quote.gif" onclick="insert_quote('[quote=i9.ioa^n1k]testing this out@![/quote] Why doesn\'t this work?', 'i9.ioa^n1k')" border="0" alt="Quote this comment" title="Quote this comment" /> the insert_quote function is function insert_quote(quote, username) { surroundText(document.csystem_textarea.message, '[quote=' + username + ']'+quote+'[/quote]'); } Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 30, 2008 Share Posted July 30, 2008 are you using PHP5+ ? if so, you can use json_encode() when printing the data: <?php $quote = "[quote=i9.ioa^n1k]testing this out@![/quote] Why doesn\'t this work?"; print '<img src="/csys/themes/I92/images/icons/quote.gif" onclick=\'insert_quote('.json_encode($quote).', "i9.ioa^n1k")\' border="0" alt="Quote this comment" title="Quote this comment" />'; ?> Quote Link to comment Share on other sites More sharing options...
ionik Posted July 31, 2008 Author Share Posted July 31, 2008 are you using PHP5+ ? if so, you can use json_encode() when printing the data: <?php $quote = "[quote=i9.ioa^n1k]testing this out@![/quote] Why doesn\'t this work?"; print '<img src="/csys/themes/I92/images/icons/quote.gif" onclick=\'insert_quote('.json_encode($quote).', "i9.ioa^n1k")\' border="0" alt="Quote this comment" title="Quote this comment" />'; ?> json_encode won't work Anyways i solved this problem with a simple modified trim. function deeptrim($quote) { $quote = str_replace(' ', ' ', $quote); $quote = trim($quote); $quote = addslashes($quote); return $quote; } 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.