ashrobbins87 Posted March 26, 2009 Share Posted March 26, 2009 Hi guys and girls, I was wondering if anyone could help me out with a little problem I'm having. I have built a page which retrieves user details from a database and displays a list of names in a drop down list, this works fine. I then want the user to select a name and click a "View" button to display the details of that person in a pop up window. The pop up opens fine except the data which it displays is always for the last person in the drop down list, IOW the person that the loop finishes on. Does anybody know what I'm doing wrong? My code is below. <script type="text/javascript"> function eventWindow(url) { event_popupWin = window.open(url, 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=450,height=500'); event_popupWin.opener = self; } </script> <?php $mysqli = mysqli_connect("localhost","root","root","opp_group"); //Get list of users in drop down $getUsers_sql ="SELECT id, firstname, surname FROM cms_users ORDER BY firstname"; $getUsers_res = mysqli_query($mysqli, $getUsers_sql)or die(mysqli_error()); echo "<form method=\"POST\" action=\"\" > <select name=\"users\">"; while ($row = mysqli_fetch_assoc($getUsers_res)) { echo '<option value="' . $row['id'] . '">' . $row['firstname'] . ' ' . $row['surname'] . '</option>'; $id = $row['id']; } echo "</select> <a href=\"javascript:eventWindow('../user.php?i=".$id."');\"> <input type=\"submit\" name=\"viewuser\" value=\"View\" /> </a>"; ?> </form> Link to comment https://forums.phpfreaks.com/topic/151250-javascript-popup-not-receiving-correct-variable/ Share on other sites More sharing options...
monkeytooth Posted March 26, 2009 Share Posted March 26, 2009 Sounds like what your tempting to do would involve a bit of javascript to update the link as well upon change of the selection. Why not try putting an onChange event in your select source. ie: <script type="text/javascript"> function eventWindow(url) { event_popupWin = window.open(url, 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=450,height=500'); event_popupWin.opener = self; } </script> <?php $mysqli = mysqli_connect("localhost","root","root","opp_group"); //Get list of users in drop down $getUsers_sql ="SELECT id, firstname, surname FROM cms_users ORDER BY firstname"; $getUsers_res = mysqli_query($mysqli, $getUsers_sql)or die(mysqli_error()); echo "<form method=\"POST\" action=\"\" name=\"userinfobox\" > <select name=\"users\" onChange=\"javascript:eventWindow(\'../user.php?i=\' + document.userinfobox.users.options[document.userinfobox.users.selectedIndex].value)>"; while ($row = mysqli_fetch_assoc($getUsers_res)) { echo '<option value="' . $row['id'] . '">' . $row['firstname'] . ' ' . $row['surname'] . '</option>'; $id = $row['id']; } echo "</select>"; ?> </form> This is just a thought not tested but should work with a bit of tweaking. The concept follows that of the selection box found on this page. http://crecs.org/index.php?yb=jbrowse It just invokes your javascript rather then the one that I use to make it reload, but it follows the basis of what your attempting to do. Like I said I didnt test this but if it doesnt work out right you should only need to tweak it a bit to get it to work, this way when a selection is made on the select box it invokes the script rather then updates the link, updating the link doesnt work they way you have it cause you would need more javascript to write to the existing document. The way you have it currently is the last ID found in the loop is the last ID to be used as the link no changes upon selection Link to comment https://forums.phpfreaks.com/topic/151250-javascript-popup-not-receiving-correct-variable/#findComment-794549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.