Good morning. I want to cause the result of the cpf variable to be displayed in the input 'receive'.
practicando.php
<head>
<meta charset="UTF-8"/>
<script type="text/javascript" src="pratica.js"></script>
</head>
<body>
<fieldset style="width:50%; margin: 0px auto; ">
<legend>Colocando PONTO no CPF</legend>
<form id="form">
<label for="cpf">CPF</label>
<input type="number" name="cpf" placeholder="Sem pontos e traço" required />
<input type="submit" value="ENVIAR" name="button"/><br/><br/>
<input name='recebe' id="recebe" readonly style='width:100%;'/>
</form>
</fieldset>
</body>
validaPraticando.php
$cpf = $_POST['cpf'];
if(strlen($cpf) == 11){
$pegaCpf = substr($cpf,0,3).'.'.substr($cpf,3,3).'.'.substr($cpf,6,3).'-'.substr($cpf,9,2);
echo json_encode($pegaCpf);
}else{
echo json_encode("CPF Invalido");
}
pratica.js
$(documento.ready(function(){
$("#form").on("submit",function(e){
e.preventDefault();
var data = $("#form").serialize();
$.ajax({
url: "validaPraticando.php",
data: data,
method: "POST",
dataType: "json",
success: function(data){
$("#retorno").val(data);
},
error: function(){
alert("erro na requisição");
}
});
});
});