I am trying to use javascript functions in a php echo statement. The showme and onclick function are being used and values must be passed in the showme function.
The code below is not working.
echo"
<ul>
<li><a href='javascript:void(0);' onclick='showme('Test','','10.70725','-61.55391','','Tester');' >$id</a></li>
</ul>
";
How do I fix this?
echo"
<ul>
<li><a href='javascript:void(0);' onclick=\"showme('Test','','10.70725','-61.55391','','Tester');\" >$id</a></li>
</ul>
";
So don't echo so much using PHP simply make it like this, and also add the " quotes around your showme()
<ul>
<li>
<a href="javascript:void(0);" onclick="showme('Test','','10.70725','-61.55391','','Tester');"><?php echo $id; ?></a>
</li>
</ul>
Edit: As you said you are running this in a while loop you can do it like this
I assume that you are extracting the data from the database
<?php
while($blah = mysqli_fetch_array($fetch_blah)) {
?>
<!--HTML Part Goes Here-->
<ul>
<li>
<a href="javascript:void(0);" onclick="showme('Test','','10.70725','-61.55391','','Tester');"><?php echo $blah['id']; ?></a>
</li>
</ul>
<?php
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With