Jump to content

add into variable


doddsey_65

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/217516-add-into-variable/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/217516-add-into-variable/#findComment-1129287
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/217516-add-into-variable/#findComment-1129297
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.