Get value from div

Asked

Viewed 61 times

1

I want to get the value of div when I click. The problem is that it creates a div in the foreach. I want to get the id, to then pass this value to another page and use to make a SELECT in the Sqlite database.

$array_resultadoss = array(); //array   
$array_resultadoss=select($dir, $base, $i);
$titless = ""; //variable inicialize 

foreach($array_resultadoss as $key =>$value){
    $titless .= "<div class=dois>".$value['id']."</div>";//save in variable value
}

echo" 
    <td class='td_today'>
        <div class=divday style='cursor:pointer' onclick='popup(\"_popup_cal.php?jour=$i&moisEcris=$months[$moisaff]&annee=$year&mois=$month&txttitle=$txttitle&txtstart=$txtstart&txtend=$txtend&txtdescription=$txtdescription&maj=$maj&clean=1&numevent=$numevent\",400,300)';>
        ".$titless."</div>
    </td>";
}      
  • 1

    How are you trying to regain value in _popup_cal.php?

  • By the GET method

  • By the GET method you have to pass the variable on the link.

  • Right and pass here onclick='popup("_popup_cal.php? id=$key&jour=$i&moisEcris=$months[$moisaff]&annee=$year&mois=$month&txttitle=$txttitle&txtstart=$txtstart&txtend=$txtend&txtdescription=$txtdescription&maj=$maj&clean=1&numevent=$numevent",400,300)'

  • Where I can’t see $array_resultadoss nor $key nor $value...

  • Not id=$key? So how should I do?

  • Let me get this straight you want every element of $array_resultadoss have a <td class='td_today'>?

  • I have only this div that shows all the events of the database. I want to click on the div, give me the id (value) in the record that I clicked.

Show 3 more comments

1 answer

2


First of all, I advise you to refactor your code, logic is not cool. But in keeping with what you’ve already done, I believe that the way to achieve what you expect is by generating the function popup() of Javascript for each <div>. I made the adjustments in the code and it was like this:

$array_resultadoss = array();
$array_resultadoss = select($dir, $base, $i);
$titless = '';

foreach ($array_resultadoss as $key => $value) {
    $titless .= "<div class=dois onclick='popup(\"_popup_cal.php?jour=$i&moisEcris=$months[$moisaff]&annee=$year&mois=$month&txttitle=$txttitle&txtstart=$txtstart&txtend=$txtend&txtdescription=$txtdescription&maj=$maj&clean=1&numevent=$numevent&num_div={$value['id']}\",400,300)';>" . $value['id'] . '</div>';
}

echo "<td class='td_today'>
          <div class=divday style='cursor:pointer'>
              " . $titless . "
          </div>
      </td>";

Then in _popup_cal.php you will have $_GET['num_div']

Browser other questions tagged

You are not signed in. Login or sign up in order to post.