If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Auto-populate text box in Form2 once data is pulled down from Form1

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-09, 14:49
jawshoouh jawshoouh is offline
Registered User
 
Join Date: Jun 2009
Posts: 13
Auto-populate text box in Form2 once data is pulled down from Form1

OK, I've got a drop-down that displays contents from the MySQL DB properly in a table (table is ugly, but I'm working on the layout). Here's the HTML of the page that shows the drop-down and table (there's 48 entries, I've truncated it to 5):
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="selectuser.js"></script>
</head>
<body>
<form>
<span class="headingText">Select the name: </span>
<select name="users" class="formText" onChange="showUser(this.value)">
    <option selected="selected">Select...</option>
    <option value="1">A1</option>
    <option value="2">B2</option>
    <option value="3">C3</option>
    <option value="4">D4</option>
    <option value="5">E5</option>
</select>
<br />
</form>
<div class="contentText" id="txtHint">Site information will be listed here.</div>
</body>
</html>
And the selectuser.js code:
Code:
var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="getuser.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
And the getuser.php code:
PHP Code:
<?php

$q
=$_GET["q"];

$hostname="SERVER";
$username="USERNAME";
$password="PASSWORD";
$dbname="DBNAME";
$usertable="TABLENAME";

mysql_connect($hostname,$username$password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname);

$query "SELECT * FROM $usertable WHERE id = $q";

$result mysql_query($query);

echo 
"<table border='1'>
<tr>
<th>Name</th>
<th>RunBy</th>
<th>Director</th>
<th>Address</th>
<th>City</th>
<th>District</th>
<th>Province</th>
<th>Telephone</th>
<th>LatLong</th>
<th>GeoNotes</th>
<th>Comments</th>
</tr>"
;

while(
$row mysql_fetch_array($result))
  {
  echo 
"<tr>";
  echo 
"<td>" $row['Name'] . "</td>";
  echo 
"<td>" $row['RunBy'] . "</td>";
  echo 
"<td>" $row['Director'] . "</td>";
  echo 
"<td>" $row['Address'] . "</td>";
  echo 
"<td>" $row['City'] . "</td>";
  echo 
"<td>" $row['District'] . "</td>";
  echo 
"<td>" $row['Province'] . "</td>";
  echo 
"<td>" $row['Telephone'] . "</td>";
  echo 
"<td>" $row['LatLong'] . "</td>";
  echo 
"<td>" $row['GeoNotes'] . "</td>";
  echo 
"<td>" $row['Comments'] . "</td>";
  echo 
"</tr>";
  }
echo 
"</table>";
?>
Minus the output table formatting which I'm still learning how to fix, it works swimmingly. However, I want to know if this is possible:

The information that's dumped into the LatLong cell, is there any way to make that same info auto-populate another text field in another form on the same page (id="flyhere") once it shows up in the table? And re-populate it once the selection in the dropdown menu is changed?

Or make the cell in that table clickable, so if info does populate that cell, you can click on it and have it populate the other "flyhere" text box in the other form?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On