Displaying Database's Row Value In Javascript Function In Php
$finalval=0; while($row = mysql_fetch_array($result)) { $finalval=$finalval. ''. $row['Title'] . '
Solution 1:
When you call showContent()
, you have to put the ID you want to show between ", like this:
$finalval=$finalval. "<a href='#' onClick='showContent(\"".json_encode($row['ID'])."\");'>". $row['Title'] . "</a> <br>"
Solution 2:
Try this one
<?PHP$result = mysql_query($query);
$finalval = 0;
while ($row = mysql_fetch_array($result)) {
$finalval = $finalval."<a class='show-content' data-id='". $row['ID'] ."' href='#' >". $row['Title'] ."</a> <br>" ;
}
echo$finalval;
?><scriptlanguage="javascript"type="text/javascript" >var element = document.querySelectorAll(".show-content");
for (var link in element) {
element[link].onclick = function() {
showContent(this.getAttribute('data-id'));
};
}
functionshowContent(value){
alert(value);
}
</script>
Post a Comment for "Displaying Database's Row Value In Javascript Function In Php"