Results 1 to 7 of 7

Thread: new window with a variable help

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default new window with a variable help

    hello guys/gals i have a problem with Javascript in php. i want to open a new window from a button. the problem is i am not that adept with javascript

    ok here it goes i will display a list of names in a table and there is a view button in each names here's the code.
    Code:
    <table width="50%" border="2" cellspacing="0" cellpadding="1">
      <tr>
        <td width="84%">Name</td>
        <td width="16%">View</td>
      </tr>
      <?php 
      require ("db.php");
      
      $result=mysql_query("select * from names");
      $while($row=mysql_fetch_array($result))
      ?>
      <tr>
        <td><?php echo $row['name']?></td>
        <td><label>
          <input type="submit" name="button" value="View" onclick="javascript:newwindow();" />
        </label></td>
      </tr>
    </table>
    now i need to pass a variable in the new window with the id of the said name the problem is i don't know where to put the variable $row['id'] to pass in the new window. can you guys help me with the code for the script of new window with a variable in it. the new window is a new page let say details.php and in it is a sql to display all the details regarding the name the sql will need an id that's why i need to pass a variable in the new windoow.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    I believe that you can do this without the need for javascript.

    try this

    PHP Code:
    <form action="newpage.php" target="_blank" method="POST"
    then add another line before the submit button:
    PHP Code:
    <td type="hidden" name="id" value=".<?php $row['id']; ?>.">
    Then in newpage.php, which should open in a new window

    PHP Code:
    $id=$_POST['id']; 
    then after that the code to access the database, retrieve the record matching $id and to display the results.

  3. #3
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Why are there dots?

    PHP Code:
    <td type="hidden" name="id" value="<?php $row['id']; ?>">
    - Josh

  4. #4
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Probably because I was having a 'dot' fuzzy moment from my painkillers.

    Thanks for spotting it.

  5. #5
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    hehe
    - Josh

  6. #6
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks for the rep forum sorry for the delay of reply

    Ok that solves the problem.

    one more thing how can i open the window in maximize mode? thanks again everyone
    Last edited by angelrovin; 09-22-2009 at 05:18 AM.

  7. #7
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Javascript window.open does not support opening a window fullsize, you could have a look at this link though:

    http://www.pbdr.com/jscript/windfull.htm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •