scdawg Posted September 7, 2012 Share Posted September 7, 2012 I have a while loop that displays all files associated with a project that display in a table. I want to use a button to open those files in a popup. My problem is that all the buttons (one generates per file), open the same file instead of their respective files, which is the first file displayed. If I do use a simple link (href), I can open the correct file, but it doesn't display in a popup, which is a problem. Does anyone have any suggestions on how to use a link or button to open the correct files in a popup? Below is my code: <? "<table border='1' cellspace='10'>\n". "<BR><BR>\n". "<tr><th align='center' colspan='5'><font size'4'>Stored Documents</font></th></tr>\n". "<tr><th align=center width='300'>Date Added</th>\n". "<th align=center width='450'>Document Title</th>\n". "<th align=center width='450'>File Name</th>\n". "<th colspan='2'> </th>\n". "</tr>\n"; While(list($date, $filename, $title) = mysql_fetch_array($resultd)) { echo "<tr>\n". "<td align=center>$date</td>\n". "<td align=center>$title</td>\n". "<td align=center><a href='docs/$coid/$filename'>$filename</a></td>\n". "<td align=center><input type='hidden' value='$filename' name='file_name'></input></td>\n". "<td align=center><input type='button' value='View Docs' onclick='return docview(); return false'>\n". "</tr>\n". } "</table>\n"; ?> <!-- Document open var filename = document.getElementById("file_name").value; var compid = document.getElementById("comp_id").value; function docview(url) { newwindow = window.open('/'+'docs/'+compid+ '/' +filename,'DocViewer','width=800,height=600,top=150,left=350,scrollbars=1,status=1'); if (window.focus) {newwindow.focus()} return false; } //--> </script> Quote Link to comment https://forums.phpfreaks.com/topic/268130-whileloop-popup-issue/ Share on other sites More sharing options...
MMDE Posted September 7, 2012 Share Posted September 7, 2012 I have a while loop that displays all files associated with a project that display in a table. I want to use a button to open those files in a popup. My problem is that all the buttons (one generates per file), open the same file instead of their respective files, which is the first file displayed. If I do use a simple link (href), I can open the correct file, but it doesn't display in a popup, which is a problem. Does anyone have any suggestions on how to use a link or button to open the correct files in a popup? Below is my code: <? "<table border='1' cellspace='10'>\n". "<BR><BR>\n". "<tr><th align='center' colspan='5'><font size'4'>Stored Documents</font></th></tr>\n". "<tr><th align=center width='300'>Date Added</th>\n". "<th align=center width='450'>Document Title</th>\n". "<th align=center width='450'>File Name</th>\n". "<th colspan='2'> </th>\n". "</tr>\n"; While(list($date, $filename, $title) = mysql_fetch_array($resultd)) { echo "<tr>\n". "<td align=center>$date</td>\n". "<td align=center>$title</td>\n". "<td align=center><a href='docs/$coid/$filename'>$filename</a></td>\n". "<td align=center><input type='hidden' value='$filename' name='file_name'></input></td>\n". "<td align=center><input type='button' value='View Docs' onclick='return docview(); return false'>\n". "</tr>\n". } "</table>\n"; ?> <!-- Document open var filename = document.getElementById("file_name").value; var compid = document.getElementById("comp_id").value; function docview(url) { newwindow = window.open('/'+'docs/'+compid+ '/' +filename,'DocViewer','width=800,height=600,top=150,left=350,scrollbars=1,status=1'); if (window.focus) {newwindow.focus()} return false; } //--> </script> The first part of your code does nothing, because you don't save it to a variable or print it to screen... o.O Quote Link to comment https://forums.phpfreaks.com/topic/268130-whileloop-popup-issue/#findComment-1376137 Share on other sites More sharing options...
scdawg Posted September 7, 2012 Author Share Posted September 7, 2012 So how do you suggest fixing it?? Quote Link to comment https://forums.phpfreaks.com/topic/268130-whileloop-popup-issue/#findComment-1376144 Share on other sites More sharing options...
Christian F. Posted September 7, 2012 Share Posted September 7, 2012 The same way you go about sending everything else to the client, or saving it in a variable..? Quote Link to comment https://forums.phpfreaks.com/topic/268130-whileloop-popup-issue/#findComment-1376199 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.