Javascript link on/off in PHP - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Thursday, April 27, 2023

Javascript link on/off in PHP

I am trying to change a Javascript link for open/close a div in PHP but no matter what I change I get error. This is the Javascript:

    <script type="text/javascript" language="JavaScript">
    function ReverseDisplay(d) {
    if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
    else { document.getElementById(d).style.display = "none"; }
    }
    </script>

Here is the link I now use without the PHP below: <a href="javascript:ReverseDisplay('<?php echo $row["id"]; ?>')">Open/Close</a>

Here is the PHP I try add it to:

        <?php

            // Use foreach to access all the courses data
            foreach ($All_courses as $course) { ?>
            <tr>
                <td>
                    <?php
                    if($course['status']=="1")

                        echo
"<a href=deactivate.php?id=".$course['id']."><img src='icons/off.png' width='16' height='16'></a>";
                    else
                        echo
"<a href=activate.php?id=".$course['id']."><img src='icons/on.png' width='16' height='16'></a>";
                    ?>
            </tr>
            <tr>
              <td valign="top" class="sqlinfosub"><div class="article" id="<?php echo $row["id"]; ?>" style="display:none;">Here are the notes: This is just a test.</div></td>
            </tr>
           <?php
                }
                // End the foreach loop
           ?>

Does anyone have a solution on this?

I tryed to add onclick in the PHP link:

"<a href=deactivate.php?id=".$row['id']." onclick='ReverseDisplay('$course['id']')'><img src='icons/off.png' width='16' height='16'></a>";

But then I get: Parse error: syntax error, unexpected string content "", expecting "-" or identifier or variable or number



source https://stackoverflow.com/questions/76114063/javascript-link-on-off-in-php

No comments:

Post a Comment