Greetings!
I have here simple ajax request
<html>
<title></title>
<head>
<script type="text/javascript" src="../js/prototype.js"></script>
<script>
function sendRequest() {
new Ajax.Request("test.php",
{
method: 'post',
postBody: 'name='+ $F('name'),
onComplete: showResponse
});
}
function showResponse(req){
$('show').innerHTML= req.responseText;
}
</script>
</head>
<body>
<form id="test" onsubmit="return false;">
Name: <input type="text" name="name" id="name" >
<input type="submit" value="submit" onClick="sendRequest()">
</form>
<div id="show"></div>
<br/><br/>
</body>
</html>
and this is my test.php
<?php
if($_POST["name"] == "")
echo "name is empty";
else
echo "you typed ".$_POST["name"];
?>
Its a simple search box.
The code works well, my problem is when I tried to add some spices that when the page is not submitted, I want to display the list of my records inside my database. And when the user hit the the search button, the displayed record will hide and will show the search result.
I tried to fix this using this code:
<?php
if ((isset ($_POST)) {
if($_POST["name"] == "")
echo "name is empty";
else
//mysql query
}
else {
..//display records.
}
Any help is really appreciated.