简体   繁体   中英

Get value from a link to display a <div> in the same page

I have a <table> in my Research.php page like that


| Date | User| Group | ETC |

The column Date is a link. Here is a sample of the <table> creation :

while($line= mysqli_fetch_array($warning))
{
echo "<tr>";
    echo"<td ><a href=\"\" onclick=\"javascript:visibilite('Details'); return false;\">".date('d/m/Y H:i:s', strtotime($line['Date_heure']))."</a></td>";

The javascript code :

<script>
        function visibilite(thingId)
        {
            var targetElement;
            targetElement = document.getElementById(thingId) ;
            if (targetElement.style.display == "none")
            {
                targetElement.style.display = "" ;
            } else {
                targetElement.style.display = "none" ;
            }
        }
        </script>

And the <div> placed in the same page:

<div id="Details" style="display:none;">

Everything work well. My problem is that I want the div#Details to change according to the date clicked. What my code do is that it hides the div#Details but display the same informations. I want to be able to get the value clicked to change div#Details according to the data in my db. I tried to add in the <a> href='Research.php?Number=".$line['Number']."' but nothing happens when I click a link.

I don't know if i have to use JQuery and how, or if I'm doing something wrong

 function visibilite(thingId)
        {
            var targetElement;
            targetElement = document.getElementById(thingId) ;
            if (targetElement.style.display == "none")
            {
                targetElement.style.display = "block" ;
            } else {
                targetElement.style.display = "none" ;
            }
        }

just replace "" with block and it will start working

if you want display means using block

<script>

function visibilite(thingId)
        {
            var targetElement;
            targetElement = document.getElementById(thingId) ;
            if (targetElement.style.display == "none")
            {
                targetElement.style.display = "block" ;
            } else {
                targetElement.style.display = "none" ;
            }
        }
                </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM