I have two pages index.php
and search.php
, both have a search box. If the user enters the name to be searched in the index.php
Textarea and clicks on submit button the content of the Textarea should be loaded in the search.php
page.
index.php
<form action="search.php" method="post">
<div>
<input type="text" name="query_data" placeholder="Who would you like to find today?">
</div>
<div>
<input type="submit" name="submit" value="SEARCH"></input>
</div>
</form>
search.php
<div>
<div>
<input type="text" name="search" id="search" placeholder= <?php echo $_POST["query_data"]; ?> >
</div>
<div>
<input type="submit" name="submit" value="SEARCH" onclick="func()"</input>
</div>
</div>
I want the name searched in the index.php
page to be the placeholder in the search.php
page.
The user would have to click on the search button of the search.php
page to load the function func()
and get the answers.
This code is wrong and is not working. It is giving an error that the query is undefined. Please Help! Thanks a lot!
I have added the Javascript file also. It has Ajax and is getting the right result when used on the search.php page. The problem is not with the Javascript though!
<script type="text/javascript">
function func()
{
var tosearch=document.getElementById("search").value;
if(tosearch==="")
print("<center><b>Nothing To Search For!!</b></center>");
else
{$.ajax({
type: 'post',
url: 'page2.php',
data: {'tosearch' : tosearch},
dataType: "html",
success: function (result) {
print(result);
}
});
}
}
function print(result){
document.getElementById("output").innerHTML=result;
}