Q:

PHP and AJAX to get a variable back

I'm using PHP and AJAX to make a post in the page.  Request.php requests the second return.php.  But I dont get the return:
request.php
<script src="jquery-3.3.1.min.js"></script>
</head>

<script type="text/javascript">  
   function getnumber(){  
    var number=document.getElementById("number").value;  
    alert(number);  
    }

    function post(){
     var numberp=document.getElementById("number").value;  
     $.post('return.php',{postnumber:numberp}, 
     function(data){ 
     var result = $('#numberp').html(data); 
     return result; });
    }
</script>

<form>
    Enter No:<input type="text" id="number" name="number"/><br/>  
    <input type="button" value="Get number" onclick="getnumber()"/>  
</form> 

<form>
    Enter No:<input type="text" id="number" name="number"/><br/>  
    <input type="button" value="Get number processed" onclick="post()"/>  
</form>

return.php
<? php
function returnString() {
$post_number = $_POST['postnumber'];
echo "the name entered ->", $post_number, " <- hier";
}
returnString();
? >

Expected result is the number is returned by return.php

A:

First thing is id should be unique.you are using one id= number in two places which creates ambiguity. Check this working code. 
request.php
<script type="text/javascript">
   function getnumber(){
    var number1=document.getElementById("number1").value;
    alert(number1);
    }

    function post(){
     var number2=document.getElementById("number2").value;
     $.post('return.php',{postnumber:number2},
     function(data){
     var result = $('#numberp').html(data);
     console
     return result; });
    }
</script>

<form>A
    Enter No:<input type="text" id="number1" name="number1"/><br/>
    <input type="button" value="Get number" onclick="getnumber()"/>
</form>

<form>
    Enter No:<input type="text" id="number2" name="number2"/><br/>
    <input type="button" value="Get number processed" onclick="post()"/>
</form>
<div id="numberp"></div>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>

return.php
<? php

function returnString() {
    $post_number = $_POST['postnumber'];
    echo "the name entered ->", $post_number, " <- hier";
}
returnString();
? >

