I'm having a problem with php javaScript echo. I wanna fire a javaScript functions for buttons which are dynamically created by using echo.
When i test it without echo, functions are using properly. But when I create it using echo, it doesn't work.
Here is the echo in pages.php:
$cont.='<div style="border-bottom: 1px solid #A2DBFF; padding-bottom: 25px; padding-top: 20px; margin-bottom: 10px; margin-left: 25px;">';
$cont.='<div class="SUBH">
<input type="text" id="txtNEWHEADING" name="txtSubNam" placeholder="The new heading" />
</div>';
$cont.='<div class="PTAG">
<p>
<textarea rows="5" id="disNEWCONT" cols="70" placeholder="add a discription here.." name="txtCont"></textarea>
</p>
</div>';
$cont.='<div class="IMGTAG">
<input type="file" id="imgNewIMAGE" />
<button class="btnSav" type="submit" onclick="SaveContent()" id="btnNEWCONTENT" style="margin-left: 300px;" />save</button>
</div>';
$cont .= '</div>';
And the javaScript is here:
$cont .= '
<script type="text/javascript">
$("#btnNEWCONTENT").click(function(){
alert("hi there..");
$.ajax({ url: \'ajax.php\',
data: {action: \'test\'},
type: \'post\',
success: function(data) {
alert(data);
}
});
});
</script>
';
echo $cont;
Please help.