JS send value to input hidden HTML not work

本秂侑毒 提交于 2019-12-13 23:16:44

问题


I have a very big problem. This is my code:

function calcolaGiorni() {
	var data1 = document.getElementById('set').value;
	var data2 = document.getElementById('set1').value;
	var diffTempo = Math.abs(data2.getTime() - data1.getTime());
	var diffGiorni = Math.ceil(diffTempo / (1000 * 3600 * 24));
	var prezzo = 500;
	var totale = diffGiorni*prezzo;
	document.getElementById('stampaTot').value = totale;
}
<input type="hidden" name="prezzoTotale" id="stampaTot">

The hidden input will contain the operation result, but anything don't work.


回答1:


Try stepping through your code in the browser debugger. Verify that your variables are numbers and can result in valid results.

Check in the console (ctrl+shift+j in Chrome) to see the results, or use an alert box, as below.

function calcolaGiorni() {
var data1 = document.getElementById('set').value;
var data2 = document.getElementById('set1').value;
var diffTempo = Math.abs(data2.getTime() - data1.getTime());
var diffGiorni = Math.ceil(diffTempo / (1000 * 3600 * 24));
var prezzo = 500;
var totale = diffGiorni*prezzo;
//check variable values for anything suspect based on the original inputs
alert(totale) //shows an alert box for the value totale
console.log(totale) //view the variable in the console 
document.getElementById('stampaTot').value = totale;
}


来源:https://stackoverflow.com/questions/54579867/js-send-value-to-input-hidden-html-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!