xTRIFAC70Rx xTRIFAC70Rx - 3 months ago 37
PHP Question

Adding a Javascript popup link in a foreach loop laravel

I have a foreach loop and i want to add a javascript popup within it.
I have to code for the loop and the popup box, im just struggling with how to write the link, please see below.

This is the popup link i want to add to my foreach loop:

<a onclick="popupCenter('http://www.example.com', 'myPop1',450,450);" href="javascript:void(0);">CLICK TO OPEN POPUP</a>

so :

foreach($data as $key){

echo "<tr><td>" . $key->value1 . "</td>";
echo "<tr>" . $key->value2 . "</td>";
echo "<tr>" . THIS IS WHERE I WANT TO ADD THE POPUP . "</td>";



You have some bad HTML where you open one type of tag but you close another type (tr vs. td).

I also prefer not to print a lot of HTML with echo. It tends to get messy and hard to read. Try this:

foreach($data as $key){
    <td><?= $key->value1 ?></td>
    <td><?= $key->value2 ?></td>
    <td><a onclick="popupCenter('http://www.example.com', 'myPop1',450,450);" href="javascript:;">CLICK TO OPEN POPUP</a></td>