To calculate the days is like this:
function diferencaEntreDias(dataIni, dataFim){//recebe a data no formato MM/dd/yyyy
var ONE_DAY = 1000 * 60 * 60 * 24;//Variável que representa um dia em milissegundos
var date_ini_ms = new Date(dataIni).getTime();//variável que representa a data incial em ms
var date_fim_ms = new Date(dataFim).getTime();//variável que representa a data final em ms
var diferenca = date_fim_ms - date_ini_ms;//diferenca, em ms, entre as datas
return Math.round(diferenca/ONE_DAY);//diferenca, em dias, entre as datas
}
To calculate just do:
window.alert(qtdDias * 10);
remembering that it is an Alert for you to see the value of the calculation.
The example to update the DIV is this:
<!DOCTYPE html>
<html>
<head>
<title>teste</title>
<meta charset="UTF-8" />
<script type="text/javascript">
function gravar(){
var titulo = document.getElementById("txtTitulo").value;
var subtitulo = document.getElementById("txtSubtitulo").value;
var div = document.getElementById("divResultado");
div.innerHTML = "<h1>" + titulo +"</h1>"+ "\n" + subtitulo;
}
</script>
</head>
<body>
<div>
<label>Título:</label>
<input type="text" id="txtTitulo"/>
<label>Subtítulo:</label>
<input type="text" id="txtSubtitulo"/>
<button id="btnEnviar" onclick="diferencaEntreDias(passeAsDatasAqui)" >Gravar</button>
</div>
<div id="divResultado">
</div>
</body>
</html>
As you can see is an example you will need to understand to mount it properly but this is the basis.
Wow, thanks is halfway there. But there is still one thing missing that I think for me will be the most difficult, which is the question of only calculating when the user fills the two date fields To and B, how could I do that? It’s being the hardest now
– Alisson Acioli
Includes a simple example without many validations. @Alissonacioli
– Renan Gomes