I have a weird problem with my PHP and Javascript files. I have HTML content in my Database, and I want to insert that into my page. So, I get the values and pass it to the HTML page like this:
$string = preg_replace( "/|
/", "", htmlentities($formcontent) );
I get a string which I can use to pass it to my javascript, like this:
var contentform = '<?php echo $string; ?>';
Now I want to insert this HTML into my page. I've got a div set up, but if I insert it, it keeps getting treated as a string so there isn't any DOM to display.
var htmltrimmed = $.trim(contentform);
var htmlcontent = $.parseHTML(htmltrimmed);
console.log(htmltrimmed);
$('#currentform').html(htmltrimmed);
But when I check the console of check the actual div, there is just a plain string inserted.:
You see it gets treated as a string. But I really don't understand why it's acting like this.
EDIT:
This is the contentform value, I've cut some of it off, because the string is very long, but the actual value is a valid HTML string!:
<form class="form-horizontal" ><fieldset><!-- Form Name --><legend>DMN SGT</legend><!-- Multiple Radios --><div class="control-group"> <label class="control-label" for="multipleradios-0">Grund der Messebesuch</label> <div class="controls"> <label class="radio" for="multipleradios-0-0"> <input type="radio" name="multipleradios-0" id="multipleradios-0-0" value="Konkretes Interesse an Produkt" checked="checked">