My files on my directory are like this:
index.html
mobile.txt
adress.txt
country.txt
My HTML is like this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myform" method="post">
<input type="text" id="nameTxt" placeholder="Please Enter Your txt name hire"/>
<input type="submit" id="findTxt" value="search"/>
</form>
I want to display the contents of the search results:
<input type="text" id="diplayTxt" value=""/>
I tried this but it still fails:
$(document).ready(function(){
$("#myform").submit(function (event){
event.preventDefault()
var obj = document.getElementById("nameTxt").value;
var dTxt = document.getElementById("diplayTxt");
$.post("index.php", {obj:obj}, function(data){
dTxt.value = data;
});
});
});
Here is the PHP code:
<?php
$ft = $_POST['obj'];
$fh = fopen($ft.".txt", "r");
while ($line = fgets($fh))
{
echo $line;
}
fclose($fh);
?>
Please help me to fix it.