MK Jain MK Jain - 25 days ago 13
HTML Question

Copy option in php using javascript not working

I am trying to copy content from copy button in PHP using javascript.

But it is not copying.

I tried:

<a class="btn btn-primary" href="user_images/<?php echo $row['userPic']; ?>"><span class="glyphicon glyphicon-eye-open"></span> View</span></a>
<p id="#i<?php echo $row['userID']; ?>" style="display: none;">user_images/
<?php echo $row['userPic']; ?>
<button onclick="copyToClipboard('#i<?php echo $row['userID']; ?>')" class="btn btn-primary"><span class="glyphicon glyphicon-eye-open"></span> Share</span>
function copyToClipboard(element) {
var $temp = $("<input>");

Answer Source

Do not use # in id="". They are auto defined.

So, change <p id="#i<?php echo $row['userID']; ?>" to <p id="i<?php echo $row['userID']; ?>"

Hope this will work!