doddsey_65 Posted November 2, 2010 Share Posted November 2, 2010 i have some code which displays text area contents in a preview box using jquery. but this is for a forum which means the text area will contain something like word. This will just print the . I know i can replace that with str_replace but that means the contents of the textarea need to be in a variable. so how do i add it into a variable? <script type="text/javascript"> $("textarea").keyup(function () { var value = $(this).val(); $("#preview").text(value); }).keyup(); </script> <p id="preview"> Your Preview will appear here </p> Quote Link to comment https://forums.phpfreaks.com/topic/217516-add-into-variable/ Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 Sorry, but your question makes little sense. Again? Quote Link to comment https://forums.phpfreaks.com/topic/217516-add-into-variable/#findComment-1129282 Share on other sites More sharing options...
doddsey_65 Posted November 2, 2010 Author Share Posted November 2, 2010 basically when a user enters something into textarea the content of the text area is added to the <p> as you type. but when you click a bbcode button(lets say Bold) the content of the text area will be [bold]the word[/bold]. But then the preview box will also look the same because its generated using jquerys .val(). <script type="text/javascript"> $("textarea").keyup(function () { var value = $(this).val(); $("#preview").text(value); }).keyup(); </script> so how would i be able to format $("#preview").text(value); with my bbparser? Quote Link to comment https://forums.phpfreaks.com/topic/217516-add-into-variable/#findComment-1129287 Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 Is your bbcode parser client-side or server-side? Quote Link to comment https://forums.phpfreaks.com/topic/217516-add-into-variable/#findComment-1129289 Share on other sites More sharing options...
doddsey_65 Posted November 2, 2010 Author Share Posted November 2, 2010 Is your bbcode parser client-side or server-side? server side Quote Link to comment https://forums.phpfreaks.com/topic/217516-add-into-variable/#findComment-1129294 Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 Then you will need to use Ajax to send the data back to the server, have it parsed, and sent back to the client. Quote Link to comment https://forums.phpfreaks.com/topic/217516-add-into-variable/#findComment-1129295 Share on other sites More sharing options...
doddsey_65 Posted November 2, 2010 Author Share Posted November 2, 2010 that sounds a bit complicated. Any tips? Here is the code for the textarea and preview box: <textarea class="test" id="reply" name="test" style="height:350px;width:785px;"></textarea> <script type="text/javascript"> $("textarea").keyup(function () { var value = $(this).val(); $("#preview").text(value); }).keyup(); </script> <p id="preview"> Your Preview will appear here </p> And here is some of the bbcode parser: class bbParser{ public function __construct(){} public function getHtml($str){ $bb[] = "#\[b\](.*?)\[/b\]#si"; $html[] = "<b>\\1</b>"; $bb[] = "#\[i\](.*?)\[/i\]#si"; $html[] = "<i>\\1</i>"; $bb[] = "#\[u\](.*?)\[/u\]#si"; $html[] = "<u>\\1</u>"; $str = preg_replace ($bb, $html, $str); return $str; } } you can see it here: http://thevault.cz.cc/new_post.php?forum=1&topic=65 You will need to login with username:public and password:public then click Post reply at the bottom left. Quote Link to comment https://forums.phpfreaks.com/topic/217516-add-into-variable/#findComment-1129297 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.