Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get this pop up box to display the value of the div clicked?
    text
    copied!<p>I have a search box that you type in a name and a list of matching names come up using ajax. I also have a <em>div</em> that pop ups alongside the names that when clicked, another <em>div</em> pops up showing the name of the person the <em>div</em> is matched with inside of it.</p> <p>Here is my code:</p> <p>PHP:</p> <pre><code>&lt;?php require 'core.inc.php'; require 'connect.inc.php'; if (!empty($_GET['letter'])) { $letter = $_GET['letter']; $query = "SELECT `first name`, `last name` FROM `users` WHERE `first name` LIKE '".$letter."%'"; $query_run = mysql_query($query); while ($query_row = mysql_fetch_assoc($query_run)) { $first_name = $query_row['first name']; $last_name = $query_row['last name']; echo $first_name; echo " ".$last_name; ?&gt; &lt;div id="popup" onclick="popup();"&gt;&lt;input type="hidden" id="friend_name" name="friend_name" value="&lt;?php print "$first_name"; print "$last_name"; ?&gt;"&gt;&lt;/div&gt; &lt;?php } } ?&gt; </code></pre> <p>All of this works, it gets all the names and lists them out. Im setting the <em>input value</em> equal to the first name and last name so I can get it in javascript.</p> <p>Javascript:</p> <pre><code>function popup() { var popupBox = document.createElement("div"); popupBox.id = "popupBox"; popupBox.innerHTML = document.getElementById('friend_name').value; popupboxHolder.appendChild(popupBox); }; </code></pre> <p>This works fine if only one name shows up, but if two names show up and I click on the second <em>div</em> the name of the first person shows up in the pop up box not the name of the second person.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload