I am new and learning programming languages, here I want to ask on how to place javascript result (date) into input tag html.
the result seems not appear inside the input tag.
here is the function I wrote:
function updatesum() { var d1= new Date(document.getElementById("d1").value;); var d2 = new Date(document.getElementById("d2").value;); var total = (d2.getDate() - d1.getDate()) / 30 + d2.getMonth() - d1.getMonth() + (12 * (d2.getFullYear() - d1.getFullYear())); // alert(total); document.getElementById("txtTotal").value = total; return false; } and this is the html form:
<br> <form name="input" action="#" method="get" onsubmit="return false;" > Start date:<input class= "d1" type="text" name="d1" value="" id="d1" /> End Date:<input class="d2" type="text" name="d2" value="" id="d2" /> <br> <br> Total Month in fraction:<input type="text" name="total" value=" " id="txtTotal"/> <input type="submit" value="Submit" onclick="updatesum()"/> </form> the result of the function should be in input form
https://jsfiddle.net/syafieqq/c8L68bjj/2/
UPDATE correct answer