Put clock in a <TD>

Asked

Viewed 66 times

-1

I’m picking to put a clock inside a tag

I have this code for the function of the clock 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 shows me to insert the clock this way

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

But I want to put it in the code that says, "Waiting time." because it is the waiting time of the customer for the return of the call.

<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?

  • Welcome Fabio Ozuna, ever toured the site? https://answall.com/tour

2 answers

0


You can make use of Table cells Collection

Inserting the clock into the 6th cell (<td>) first-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 into the 5th cell (<td>) of the second 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>

BROWSER SUPORTE

0

Just use some tag with the ID equal to the past on document.getElementById(). I recommend using a tag that doesn’t visually change the structure of HTML, e.g.: <div>, <span>, etc....

In this example you quoted, just do so:

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

  • It worked properly for what it needed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.