Reputation: 13
I am generating this php code and want to call a JavaScript function from it.
This code is not able to call this javascript function.
<?php
echo '<li><div class="product"><a onclick="showCustomer("brand","puma")"><i class="icon-remove"></i>Shoes</a></div></li>';
?>
I have a showCustomer() function which works perfectly when called from normal html components. Is there anyway i can do this?
Upvotes: 0
Views: 38
Reputation: 1360
<?php echo '<li><div class="product"><a onclick="showCustomer(\'brand\',\'puma\')"><i class="icon-remove"></i>Shoes</a></div></li>' ;?>
should do.
Upvotes: 0
Reputation: 8408
Try using single quotes in the onclick:
<?php echo '<li><div class="product"><a onclick="showCustomer(\'brand\',\'puma\')"><i class="icon-remove"></i>Shoes</a></div></li>' ;?>
You probably will see a syntax error in the console
Upvotes: 0
Reputation: 324730
Look at your rendered HTML:
<li><div class="product"><a onclick="showCustomer("brand","puma")">...
Does that look right to you?
Upvotes: 2