0

Im having an issue with the structure of a popover. When the popover is structured like the below, it flows as designed but Im missing an ID in the onclick function.

<td align="center"><input type="image" data-placement="left" data-toggle="popover" style="height:25px; width:25px" src="<?php echo ABSPATH; ?>/uploads/settings_icon.png" data-content='<a style="cursor: pointer;" onclick="test();">Delete</a>' ></td>

When I add the missing ID into the onclick function as mentioned, it breaks the button. Please see the below code...

<td align="center"><input type="image" data-placement="left" data-toggle="popover" style="height:25px; width:25px" src="<?php echo ABSPATH; ?>/uploads/settings_icon.png" data-content='<a style="cursor: pointer;" onclick="test(**'<?php echo $id;?>'**);">Delete</a>' ></td>

This is the outcome of the above line... Any help would be greatly appreciated.

Image here

Community
  • 1
  • 1
5abre
  • 51
  • 10

2 Answers2

0

You need to escape your quotes inside the test() function call. You're already inside some single quotes that are used for the data-content attribute you're defining. When you use your first single quote inside the test() call, you're effectively ending the data-content attribute.

This question might help you further.

Alex
  • 3,029
  • 3
  • 23
  • 46
0

I don't think that it is necessary to echo $id within quotes. Try:

<td align="center"><input type="image" data-placement="left" data-toggle="popover" style="height:25px; width:25px" src="<?php echo ABSPATH; ?>/uploads/settings_icon.png" data-content='<a style="cursor: pointer;" onclick="test(**<?php echo $id;?>**);">Delete</a>' ></td>
MichaelvE
  • 2,558
  • 2
  • 9
  • 18
  • I have tried this and the error : Uncaught ReferenceError: c68c044a69b14fa3b689abd16b0e2486 is not defined at HTMLAnchorElement.onclick ((index):1) – 5abre Jul 24 '18 at 22:27
  • @MichaelvE would be correct if the ID was purely numeric, as that doesn't have to be a string in Javascript. But you have a hex value as your ID, which needs quoting as it's a string. – Alex Jul 24 '18 at 22:34