Change form javascript / php function to div

1

Personal how do I change the function below? I want to display the time in a div.

 <HTML>
 <HEAD>
 <TITLE>cronometro</TITLE>

 <script language="JavaScript">
 <!--
 function showtime()
 { setTimeout("showtime();",1000);
 callerdate.setTime(callerdate.getTime()+1000);
 var hh = String(callerdate.getHours());
 var mm = String(callerdate.getMinutes());
 var ss = String(callerdate.getSeconds());
 document.clock.face.value =
 ((hh < 10) ? " " : "") + hh +
 ((mm < 10) ? ":0" : ":") + mm +
 ((ss < 10) ? ":0" : ":") + ss;

 }
 callerdate = new Date(<?php 

date_default_timezone_set('America/sao_paulo');
$brasil = date('Y,m,d,H,i,s', time());

echo $brasil;

?>);
//-->
</script>
</HEAD>
<meta name="" content="">
<body onLoad="showtime()">
<form  name="clock"><input name="face" value=""></input>
</form> 
</body>
</HTML> 
    
asked by anonymous 17.07.2018 / 15:56

1 answer

3

For this, you need to basically change 3 rows. The first is the line

 document.clock.face.value =

What should be changed to:

document.getElementById("clock").innerHTML = 

Next, change the HTML part of the lines:

<form  name="clock"><input name="face" value=""></input>
</form> 

To:

<div id="clock"></div> 

In general, your code looks like this:

 <HTML>
 <HEAD>
 <TITLE>cronometro</TITLE>

 <script language="JavaScript">
 <!--
 function showtime()
 { setTimeout("showtime();",1000);
 callerdate.setTime(callerdate.getTime()+1000);
 var hh = String(callerdate.getHours());
 var mm = String(callerdate.getMinutes());
 var ss = String(callerdate.getSeconds());
 document.getElementById("clock").innerHTML = 
 ((hh < 10) ? " " : "") + hh +
 ((mm < 10) ? ":0" : ":") + mm +
 ((ss < 10) ? ":0" : ":") + ss;

 }
 callerdate = new Date(<?php 

date_default_timezone_set('America/sao_paulo');
$brasil = date('Y,m,d,H,i,s', time());

echo $brasil;

?>);
//-->
</script>
</HEAD>
<meta name="" content="">
<body onLoad="showtime()">
<div id="clock"></div> 
</body>
</HTML> 
    
17.07.2018 / 16:37