bobby_dummy_022
12-01-2003, 12:50 AM
Hi Everyone,
I'm sorta stuck with passing varibles and wandering if someone can help?
The following code is 2 different files (test.php, and select_user.php), test.php runs first, and when you select the image, a new window opens (select_user.php) and a list of users is displayed. I select the user I want, click on the image in the new window and the user_id is passed back to the original window, and the new window is closed. Now instead of getting the user_id I get a string passed back ('person' to be exact)... so any help is appreciated, (and I know this is a basic one)... :)
Now the code:
<test.php>
<?php
error_reporting( E_ALL );
$user_id = isset ($_POST['user_id'] ) ? $_POST['user_id']: 1;
?>
<script language="javascript">
var UserField = '';
function popUser( field ){
UserField = field;
window.open( 'select_user.php?&callback=setData', 'users', 'top=250,left=250,width=400, height=150, scrollbars=no' );
}
function setData( user_id ) {
my_field = eval( 'document.editFrm.' + UserField );
my_field.value = user_id;
}
</script>
<table cellspacing="0" cellpadding="4" border="1">
<form name="editFrm" action="test.php" method="post">
<tr>
<td align="right" nowrap="nowrap">User ID</td>
<td nowrap="nowrap">
<input type="text" name="user_id" value="<?php echo $user_id; ?>" class="text" disabled="disabled" />
<a href="#" onClick="popUser('user_id')">
<img src="update.gif" alt="Get User" border="0" />
</a>
</td>
<td align="right" width="50%" nowrap="nowrap">
<input class="button" type="submit" name="do_report" value="submit" />
</td>
</tr>
</form>
</table>
<?php
echo "User_ID is now: ".$user_id;
?>
<select_user.php>
<?php
$callback = $_GET['callback'];
?>
<script language="javascript">
function SelectUser( user_id ) {
window.opener.<?php echo $callback;?>(user_id);
window.close();
}
</script>
<tr><td align="right" nowrap="nowrap">For User:</td>
<td>
<form name="editFrm" action="test.php" method="post">
<select name="person">
<option value="1">User 1</option>
<option value="2">User 2</option>
<option value="3">User 3</option>
</select>
</td>
<td><a href="#" onClick="SelectUser('person')"> <img src="update.gif" alt="Set User" border="0" /></a></td>
</form>
</tr>
</table>
I'm sorta stuck with passing varibles and wandering if someone can help?
The following code is 2 different files (test.php, and select_user.php), test.php runs first, and when you select the image, a new window opens (select_user.php) and a list of users is displayed. I select the user I want, click on the image in the new window and the user_id is passed back to the original window, and the new window is closed. Now instead of getting the user_id I get a string passed back ('person' to be exact)... so any help is appreciated, (and I know this is a basic one)... :)
Now the code:
<test.php>
<?php
error_reporting( E_ALL );
$user_id = isset ($_POST['user_id'] ) ? $_POST['user_id']: 1;
?>
<script language="javascript">
var UserField = '';
function popUser( field ){
UserField = field;
window.open( 'select_user.php?&callback=setData', 'users', 'top=250,left=250,width=400, height=150, scrollbars=no' );
}
function setData( user_id ) {
my_field = eval( 'document.editFrm.' + UserField );
my_field.value = user_id;
}
</script>
<table cellspacing="0" cellpadding="4" border="1">
<form name="editFrm" action="test.php" method="post">
<tr>
<td align="right" nowrap="nowrap">User ID</td>
<td nowrap="nowrap">
<input type="text" name="user_id" value="<?php echo $user_id; ?>" class="text" disabled="disabled" />
<a href="#" onClick="popUser('user_id')">
<img src="update.gif" alt="Get User" border="0" />
</a>
</td>
<td align="right" width="50%" nowrap="nowrap">
<input class="button" type="submit" name="do_report" value="submit" />
</td>
</tr>
</form>
</table>
<?php
echo "User_ID is now: ".$user_id;
?>
<select_user.php>
<?php
$callback = $_GET['callback'];
?>
<script language="javascript">
function SelectUser( user_id ) {
window.opener.<?php echo $callback;?>(user_id);
window.close();
}
</script>
<tr><td align="right" nowrap="nowrap">For User:</td>
<td>
<form name="editFrm" action="test.php" method="post">
<select name="person">
<option value="1">User 1</option>
<option value="2">User 2</option>
<option value="3">User 3</option>
</select>
</td>
<td><a href="#" onClick="SelectUser('person')"> <img src="update.gif" alt="Set User" border="0" /></a></td>
</form>
</tr>
</table>