#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Trouble passing variables to popup from php while loop


    I have a while loop that displays all files associated with a project that display in a table. A project can have one file or 100 associated. I want to use a button to open those files in a popup. My problem is that all the buttons, open the same file instead of their respective files, which is the first file displayed(the variables passed to the popup never change). If I do use a simple link (href) in the php code, I can open the correct file, but it doesn't display in a popup, it opens in the same window 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:

    Code:
    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 Document" onclick="return viewdoc(); return false">
    <?
    echo
    
    "<td align=center><input type='button' value='Delete Document' name='file_delete'></input></td>\n".
    "</tr>\n";
    }
    
    echo
    "</table>\n".
    "<br><br><INPUT TYPE='submit' NAME='submit' VALUE='Submit'></p>\n".
    "<input type='hidden' name='comp_id' value='$coid'>\n".
    "</FORM>\n".
    "</BODY>\n".
    "</HTML>\n";
    
    ?>
    
    <script type="text/javascript" language="javascript">
    <!-- Document open
    
    function viewdoc() {
    var filename = document.getElementById("file_name").value;
    var compid = document.getElementById("comp_id").value;
    
    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;
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    194
    Rep Power
    76
    there is a lot of errors in your code



    first you should make the capitol W for you while loop lowercase, second make all your html attributes lowercase, third in your a href add target="_blank", next with
    Code:
    <!-- Document open
    you need to end it like this
    Code:
    <!-- Document open -->
    , next you don't need to end things in javascript with ;, and to get the value of a hidden field use
    Code:
    document.formName.elements['abcName'].value
    where formName is the forms name and abcName is the hidden fields name
  4. #3
  5. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,124
    Rep Power
    4303
    Originally Posted by jack13580
    you don't need to end things in javascript with ;
    While it's not required, it's best practice to do so.

    Originally Posted by jack13580
    Code:
    document.formName.elements['abcName'].value
    Actually, it's better to use this:
    Code:
    document.forms.formName.elements['abcName'].value
    or
    Code:
    document.forms['formName'].elements['abcName'].value
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    194
    Rep Power
    76
    Kravvitz is correct

IMN logo majestic logo threadwatch logo seochat tools logo