echo-ed HTML Element from PHP is not read in JAVASCRIPT -
so have html elements generated php since contents fetched database
i.e.
<?php ... while($row = $sqlqry->fetch_object()) { echo "<li class = 'lstoption' id = 'opt$row->name' data-value = '$row->total_count'> <h3>$row->given_reference<h3> </li>"; } ... ?>
and sample structure based on javascript
<script> $("ul li").click(function(){ alert($(this).data('value')); }); </script>
but if inject onclick=
attribute while inside echo. script executed properly. need script work echo-ed html elements php.
try using variable interpolation syntax, i.e. wrap variables around curly braces
"{$var}" take note have use double quotes("") this
"<li class = 'lstoption' id = 'opt{$row->name}' data-value = '{$row->total_count}'> <h3>{$row->given_reference}<h3> </li>"
Comments
Post a Comment