The functionality you want seems to be possible to do only on the client side (using JavaScript). I put together two variants. You can also take a look at in this answer to see other ways to send data to the server.
Via server:
To send to PHP you can do it in different ways. To make accurate descriptions of a <form>
within which you have <textare>
named . For example:
<form>
<textarea name="area_1"></textarea>
<input type="submit" value="enviar" />
</form>
In PHP you can capture this value using $_POST['area_1']
. Then you can pass this value to a variable, make the calculations you need, and then return it to the client side with echo
.
$texto_1 = $_POST['area_1'];
$comprimento = 'O comprimento da string foi: '.strlen($texto_1);
echo '
<form>
<textarea name="area_1"></textarea>
<textarea name="area_2">'.$comprimento.'</textarea>
<input type="submit" value="enviar" />
</form>
';
On the client side
You can do calculations on the JavaScript / Client side if you do not need to go through the server. In this case you may not even need <form>
.
In this case to have a textarea and a button reference you can do:
var area_1 = document.querySelector('[name="area_1"]');
var area_2 = document.querySelector('[name="area_2"]');
var botao = document.querySelector('button');
botao.onclick = function () {
area_2.value = area_1.value * 3;
}
jsFiddle: link