Juan Torres Juan Torres - 4 months ago 11x
HTML Question

JavaScript event not executed after manually modifying HTML field

i have an input text field that is automatically populated whenever a user clicks on a specific button , however if the user manually changes or deletes the text from the field , then function no longer works whenever button is re-clicked !

HTML code for the button and input field:

<button id="idButton4" onclick="setTimeUnix('idInput4')" type="button">Stop2 </button><input id="idInput4" type ="text" value="0" >

the JavaScript function that should be re-executed:

function getUnixTime(){
var date = new Date();
var unixTime= date.getTime();
var datepack=[unixTime,date];
return datepack;

function setTimeUnix(elementId){
var datepack=getUnixTime();
var element=document.getElementById(elementId);


instead of the code


try using

element.value = datepack[0];