Log in

View Full Version : new window with a variable help



angelrovin
09-18-2009, 08:42 AM
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.


<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.

forum_amnesiac
09-18-2009, 09:23 AM
I believe that you can do this without the need for javascript.

try this


<form action="newpage.php" target="_blank" method="POST">

then add another line before the submit button:


<td type="hidden" name="id" value=".<?php $row['id']; ?>.">

Then in newpage.php, which should open in a new window


$id=$_POST['id'];

then after that the code to access the database, retrieve the record matching $id and to display the results.

JShor
09-18-2009, 10:43 PM
Why are there dots?



<td type="hidden" name="id" value="<?php $row['id']; ?>">

forum_amnesiac
09-19-2009, 06:33 AM
Probably because I was having a 'dot' fuzzy moment from my painkillers.

Thanks for spotting it.

JShor
09-19-2009, 01:09 PM
hehe :)

angelrovin
09-22-2009, 04:51 AM
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

forum_amnesiac
09-22-2009, 11:49 AM
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