if you go to displayip.php what information does it contain when you give it the ipadd = 192.168.... test ip?
Basically, what the script will do is what ever is actually outputted by the file displayip.php will go into your popup div. so if you have headers and <br>s and other information other then just IP's then that will also be filled.
"How do I get the return stuff from the query to display in the box on the orig form? "
in the javascript part:
if(engine.readyState==4)
{
document.getElementById('mypopup').innerHTML=engine.responseText;
}
responseText (sp?) is the property of the engine object that actually holds what ever was put out by the file you requested. engine.readState == 4 means that once the object gets a response, reponseText will be available with the information from the file. Which means if you need the information to be formatted in a specific way or to have adddional coding on to it, you need to do it in displayip.php
so what we do here is when readState == 4, you simply use innerHTML on the popup object to insert the responseText into the popup's innerHTML.
Now, once is does so that doesnt mean it will do anything. If you want the IP that shows up to populate the textbox once it's click on you have to add an additional script and call it from the IP line in displayip.php. meaning:
<script type="text/javascript" language="Javascript">
function getthisip(ipadd)
{
engine=ajaxFunction();
ipurl='displayip.php?ip=' + ipadd;
engine.onreadystatechange=function()
{
if(engine.readyState==4)
{
document.getElementById('mypopup').style.display='';
/// just in case the div was hidden, i set it to blank because I has problems with table/block differences
document.getElementById('mypopup').innerHTML=engine.responseText;
}
}
engine.open("GET",ipurl,true);
engine.send(null);
}
function getText(text)
{
document.getElementById('ipadd').value=text;
document.getElementById('mypopup').style.display='none';
/// that hides your search box
}
/// took this code from www.w3schools.com
///it starts the ajax engine
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
return false;
}
}
}
return xmlHttp;
}
</script>
so now in your file displayip.php you would have the following:
<?PHP
/// include ("includes/nav.inc"); if this is your sites navigation, you dont need it here, this page will never be seen by your user, and it would also break the responseText results.
//Remember, you want this page to display only EXACTLY what you want to have in that popup div element.
///include "connection.php";
// wont work
include("connection.php");
/// should work
$conn=mysql_connect($localhost, $user, $password) or die("Error - Can't connect to server");
$conn_db=mysql_select_db($database, $conn) or die("Error - Can't connect to db");
/// get searchstring, convert to IP Number
$searchstring = mysql_escape_string($_GET['ipadd']);
$query = mysql_query("SELECT ip_addresses FROM ip_addresses
WHERE ip LIKE ('$searchstring%') ")
or die (mysql_error());
# now display data itself
while ($row = mysql_fetch_object ($ip_query))
{
/// remember, you have to format the IP here the way you want it to be displayed in the popup box.
// right now it will display 192.168.1.1192.293.282.192.19283.2382 since there are no breaks in the echo;
echo "<table onClick=\"getText('".$row ->ip."')\" width=\"100%\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#CCCCCC\"><tr><td>";
echo($row->ip);
echo "</td></tr></table>";
/// just a sample, will load the ip into individual tables that when clicked on will auto fill your text box
/*
but notice there isnt even a <HTML> tag in here, basially treat this page's output as if you were simply adding the code itself inside popup div
*/
}
?>
Be sure your displayip.php file is working the way you want it first, that way you know that if it's the owrking then it's the javascript that is your problem.
also, be wary or problem reporting here, you have a few cases of die() and mysql_errors()
in the AJAX, even if the PHP produces errors, it will still return a responseText so the errors is what you'll see the the popup box