I need to show the time in a text type input in a dynamic way, that is to say that it is constantly changing. For this, they recommended me to use the following function, but I have not managed to make the time show correctly. What am I doing wrong ?
Javascript
function new_clock(){
clock = new Date()
hour = clock.getHours()
minutes = clock.getMinutes()
seconds = clock.getSeconds()
print_clock= hour + " : " + minutes + " : " + seconds
document.form_clock.clock_txt.value = print_clock
setTimeout("new_clock()",1000)
}
HTML
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<section onload="new_clock()">
<form name="form_clock">
<input type="text" name="clock_txt" size="10" id="clock_txt">
</form>
The selected response works well, however when implementing the clock, it causes the module actions to load much slower.
Javascript
var today = moment().format('YYYY-MM-DD');
function new_clock(){
clock = new Date() ;
hour = clock.getHours();
minutes = clock.getMinutes() ;
seconds = clock.getSeconds() ;
print_clock= today + " " + hour + ":" + minutes + ":" + seconds;
$("#fecha_registro").val(print_clock);
setInterval(new_clock, 1000);
}
new_clock();