Setting the clock in a TD

-1

I'm picking up to put a watch inside a tag

I have this watch function code that I picked up on the internet

function startTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('txt').innerHTML =
    h + ":" + m + ":" + s;
    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}

In this example it shows me to insert the clock in this way

<body onload="startTime()">
    <p id="demo"></p>
<div id="txt"></div>

But I want to put in the snippet of code where it says "Timeout" because it is the waiting time of the client for the return of the connection.

<td>0001</td>
        <td>11:05</td>
        <td>Suporte</td>
        <td>Luciana</td>
        <td>5292 - J ALVES CONTABIL</td>
        <td>Norma</td>
        <td>Tempo de espera</td>

Could you help me?

    
asked by anonymous 04.01.2019 / 21:57

2 answers

0

You can make use of Table cells Collection

  

Inserting the clock in the 6th cell ( <td> ) of the 1st line ( <tr> )

     

rows[0].cells; x[6]

function startTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);

 var x = document.getElementById("qqId").rows[0].cells;
  x[6].innerHTML =  h + ":" + m + ":" + s;
    
    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}

startTime();
<table border="1" id="qqId">
<tr>
<td>0001</td>
<td>11:05</td>
<td>Suporte</td>
<td>Luciana</td>
<td>5292 - J ALVES CONTABIL</td>
<td>Norma</td>
<td>Tempo de espera</td>
</tr>
</table>
  

Inserting the clock in the 5th cell ( <td> ) of the 2nd line ( <tr> )

function startTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);

 var x = document.getElementById("qqId").rows[1].cells;
  x[5].innerHTML =  h + ":" + m + ":" + s;
    
    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}

startTime();
<table border="1" id="qqId">
<tr>
<td>0001</td>
<td>11:05</td>
<td>Suporte</td>
<td>Luciana</td>
<td>5292 - J ALVES CONTABIL</td>
<td>Norma</td>
<td>Tempo de espera</td>
</tr>
<tr>
<td>0002</td>
<td>11:12</td>
<td>Adm</td>
<td>Cadu</td>
<td>5298 - CADU ADMINISTRAÇÃO</td>
<td>Norma</td>
<td>Tempo de espera</td>
</tr>
</table>

    
04.01.2019 / 23:44
0

You only use some tag with the ID equal to the past in document.getElementById() . I recommend that you use a tag that does not visually alter the HTML structure, eg <div> , <span> , etc ...

In this example you mentioned, just do this:

<td>Tempo de espera: <div id="txt"></div> </td>
    
05.01.2019 / 00:07