Results 1 to 4 of 4

Thread: Complete a text field from a value selected in a <select> element

  1. #1
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Complete a text field from a value selected in a <select> element

    I'm not sure if anyone can help with my query.

    I am looking for a script that will insert the value of an <option> element from one form, into a text field in another field. The problem I have been having is that the forms are actually in different windows. Here is the script that I have for the pop-up window, which contains the <select> element from which I would like to get the value:

    Code:
    <?php
    // Get the functions file "mainFNS.php".
    require_once("../functions/mainFNS.php");
    require_once("../language/langEN.php");
    
    // Connect to the Database, because we have not called do_html_header().
    connect_db();
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Search Pupils</title>
    
    <style type="text/css" media="screen">
    @import "../styles/main.css";
    </style>
    
    </head>
    
    <body background="../images/bg.jpg" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px">
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    		<table width="100%" class="formTable" cellpadding="0" cellspacing="0" border="0">
    			<tr>
    				<th height="25">Search Users</th>
    			</tr>
    			<tr>
    				<td valign="top" bgcolor="#FFFFFF" class="content">
    				<br />
    				<input type="text" name="q" value="<?php if(isset($q)) { echo $q; } else { echo ""; }?>" class="mainField" />&nbsp; 
    				<input type="submit" name="search" value="Search" class="btn" />
    				<br />
    				<span class="small">Search using user's username, <strong>not</strong> their real name. <br />
    				Use * to list all users. </span>
    				<br />
    				<?php
    				if(isset($_POST['search'])) {
    				
    				// If the search button has been clicked, perform the search
    				
    				// Trim whitespace from the query string.
    				$q = trim($q);
    				
    				if($q!="*") {
    				$sql="SELECT * FROM tblUserData WHERE txtUsername LIKE '%$q%'  ORDER BY txtUsername ASC";
    				}
    				elseif($q=="*") {
    				$sql="SELECT * FROM tblUserData ORDER BY txtUsername ASC";
    				}
    		  			$result=mysql_query($sql);
    		  			$options="";
    						while ($record=@mysql_fetch_array($result)) {
    							$id = $record["intUserID"];
    							$name = $record["txtUsername"];
        						$options.="</option><option value=\"$id\">$name";
             				}
    						
    						// Check if there are results. If there are, display them
    						if(mysql_num_rows(mysql_query($sql)) != 0) {
    		 ?>
    		 <br />
            <select name="course" class="mainField">
              <?=$options?>
    		</option>
    		</select>
    		<?php
    						}
    						
    						// If there were no results, inform the user.
    						else {
    							echo "<br />";
    							echo "<span style=\"color: #FF0000; font-weight: bold\">No usersfound with your search of $q.</span>";
    						}
    				}
    				?>
    				<br />
    				<br />
    			 </td>
    			</tr>
    		</table>
    </form>
    
    <p>
    <div align="center">
    <a style="color: #FFFFFF; text-decoration:none" onmouseover="style.fontWeight='bold'" onmouseout="style.fontWeight='normal'" href="javascript:window.close()">[x] close</a>
    </div>
    </p>
    </body>
    </html>
    Here is the code that I have for the main window, which contains the text field (name="user") into which I would like to insert the value:

    Code:
    <?php
    // Get the functions file "mainFNS.php".
    require_once("../functions/mainFNS.php");
    require_once("../language/langEN.php");
    
    // Print the HTML header for the admin area, with the title of "Pupil Addition Form".
    do_html_header_admin("View Log Files","", "");
    
    // Check if the user is an administrator. If they aren't, prevent them from performing this task.
    check_adminLoggedIn();
    ?>
    <form method="post" name="search" action="admin_users.php">
    <table width="70%" cellspacing="0" cellpadding="5" border="0" align="center" class="formTable">
    	<tr>
    		<th align="center">Select a User</th>
    	</tr>
    	<tr>
    		<td class="row1" align="center">
    		<input type="text" style="border: 1px solid #000000" name="user"/> 
    		<input type="submit" name="add" value="Add Timetable" class="btn" /> 
    		<input type="submit" name="find" value="Find User" class="btn" onClick="window.open('searchPupil.php', '_search', 'HEIGHT=250,resizable=yes,WIDTH=400');return false;" />
       	 </td>
    	</tr>
    </table>
    </form>
    <?php
    // Print the HTML Footer, using the custom function as found in "mainFNS.php.
    do_html_footer_admin();
    ?>
    I hope that I have been thorough enoug to allow someone to answer my query, and my sincerest thanks in advance,

    Ben

  2. #2
    Join Date
    Feb 2007
    Location
    England
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default

    Have you tried cookies? They seem to be an easier choice.

    If not, then open the window from the main window and access it through the DOM.

    Like window.child(0) or something...


  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Using the below mentioned property of window object you can pass value(s) between a child (pop-up window) and parent window.

    window.opener
    You can find a demo of the above mentioned thing in this post. Follow the instruction that I had placed in my reply.

  4. #4
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks to you both, that really was a great help.

    Thanks,
    Ben

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
  •