View Full Version : onClick() and other help

07-18-2007, 02:23 AM
I have a simple page with a form that looks something like this:


<script type="text/javascript"><!--
function ShowMemberlist() {
window.open("<?php echo $domain; ?>/pages/popup.php", "memberlist", "status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,height=250,width=250");

function SelectUser(formName, obj, val) {
opener.document.forms[formName].elements[obj].value = val; self.close();
<form name="compose_pm" action="submit.php" method="POST">
<b>User Name:</b> <input id="user_name" name="user_name" type="text"> &nbsp; (<a href="ShowMemberlist()">Find a member</a>)<br />
<input name="submit" type="submit" value="Find!">


<script type="text/javascript"><!--
document.write ('<a href="#" onclick="SelectUser(\'compose_pm\', \'user_name\', \'User_1\'); return false">Select<'+'/a>');
&nbsp; User_1 &nbsp; Text

Here's what I'm trying to achieve.

A user goes to form.php and clicks on "Find a member" which opens up a popup window of popup.php. The user finds the user name he/she wants, and clicks on "Select". Javascript then should close the popup window, and put the value (which in this case is "User_1") into the appropriate input box. Currently, this script is not working. How would I make this work? Help is appreciated.

07-18-2007, 03:17 AM
The SelectUser() function should be in the popup.php not in form.php. And the "Find a member" link should be like this:

<a href="#" onclick="ShowMemberlist(); return false;">Find a member</a>

07-18-2007, 03:28 AM
Ok, that helped. Thank you very much.