In index.php:
echo <<< SEARCH
<div align="center">
<form name="SearchBar" method="post" action="index.php?">
<div align="center">
<textarea id="textinput" name="qinput" cols="80" rows="4" onclick="request_information('test',this.value)">$mesg</textarea>
<input type="submit" name="SearchButton" value="Search" />
</div>
</form>
</div>
SEARCH;
I linked a javascript file that contains the "request_information" function:
// service request function
function request_information( element_id,str )
{
// get the object used to do
var xmlhttp;
//var element_id = "test";
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// message while waiting
document.getElementById(element_id).innerHTML = "<p> request_information: Searching...</p>";
// assign the request callback
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(element_id).innerHTML="<p> request_information:" + xmlhttp.responseText + "</p>";
}else
{
document.getElementById(element_id).innerHTML= "<p> request_information: Failed</p>";
}
}
var query_str = "helluuuu";
xmlhttp.open("POST","cat.php?qu="+query_str,true);
xmlhttp.send();
}
Here I'm trying the simplest case scenario by trying to pass the value of variable "query_str" to the "cat.php" file which contains:
<?php include "connect.php"; // new process request $status = request_process(0); $q = ""; if (isset($_POST["qu"])) $q = $_POST["qu"]; else $q = "qu not passed"; echo <<<yea <h5> PID: $status </h5> <h5> Query: $q </h5> yea; ?>
I always get "qu not passed" where I print output. Before I handled the error with if statements I was getting "Undefined index 'qu' in 'cat.php' refered from 'index.php?'" in apache2 error log. Also, the 'this.value' parameter I pass doesn't work neither. All these files are in the same directory except the javascript file which is in a js/ directory..
According to W3C examples, this should work. Have I missed something crucial here?
Thankyou for your help!
dustyd

New Topic/Question
Reply



MultiQuote




|