You do not need a form to send this value to the back end, for this you can use Ajax
to know about it can see more in the documentation here.
1 - If you already have the value you want to pass to the back-end, and this value is not in an input, but rather, in text form, you can take this value through the jQuery method text()
, learn more here.
2 - Then just mount Ajax, sending the value via a request to a url that receives and treat this value.
$(function() {
$('#envio').on('click', function() {
let pts = $('#cScore').text();
$.ajax({
method: "POST",
url: "processa.php",
data: pts
})
.done(function(pts) {
setTimeout(function(){
alert( "Pontuação: " + pts );
},2000);
})
.fail(function() {
alert("Não foi enviado mas o valor é: " + pts);
})
});
})
#cScore {
display: inline-block;
background-color: #999;
color: #FFF;
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
Valor total da pontuação:
<div id='cScore'>100</div>
</div>
<button id="envio">Enviar pontuação</button>
OBS: O meu exemplo vai retornar o FAIL, pelo motivo de que a url não foi encontrada.
Friend, very grateful is exactly what I needed, I made some simple adaptations to my code and is already working. Big hug !
– Navegador
Great guy, success there!
– LeAndrade
If somehow the answer helped you to resolve your doubts, consider accepting it as an answer by clicking on this icon ✔.
– LeAndrade