Try to set the returned value to the textbox using javascript/jquery like
function pot()
{
// your code
document.getElementById("field").value="returnedvalue"; // set the result value to element with id as field
}
This will set the value of the textbox when you click on the link
<a href="#" onclick="pot();">when i click, call the function pot</a>
Note: Make sure to include the function in the file, where you are calling the function. Otherwise it won't work. If needed you can create a js file with the function (if you want to use the same function in many places) and call the js file in your php file with
<script src="jsfilename.js">