Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
How to give background-color to specific <td>? For that i have to enter position number in 3rd textbox (using java script)

I created three textboxes.

  • 1st text box takes a number as a row
  • 2nd text box takes a number as a column
  • 3rd text box takes a number(position) for highlighting that number in the table
  • how to do 3rd point in javascript
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="7.js"></script>
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="text1">
    <input type="text" name="" id="text2">

<label for="color">Which cell to color</label>
<input type="text" name="" id="color">
    <input type="button" value="Generate" onclick="h()">
    <br>

<!--javascript code-->
<script>
function h(){
var a=document.getElementById("text1").value;
var b=document.getElementById("text2").value;
var col=document.getElementById("color").value;
var g=parseInt(col);
document.write("<table border='1'>");
var c=1;
for(i=0;i<a;i++)
{
    document.write("<tr>");
    for(j=0;j<b;j++)
    {
document.write("<td>",c++,"</td>");

}
    document.write("</tr>");
   
}
document.write("</table>");

}
</script>

</body>
</html>


about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="7.js"></script>
  <title>Document</title>
</head>

<body>
  <input type="text" name="" id="text1">
  <input type="text" name="" id="text2">

  <label for="color">Which cell to color</label>
  <input type="text" name="" id="color">
  <input type="button" value="Generate" onclick="h()">
  <br>

  <!--javascript code-->
  <script>
    function h() {
      var a = document.getElementById("text1").value;
      var b = document.getElementById("text2").value;
      var col = document.getElementById("color").value;
      var g = parseInt(col);
      document.write("<table border='1'>");
      var c = 1;
      for (i = 0; i < a; i++) {
        document.write("<tr>");

        for (j = 0; j < b; j++) {
          if (parseInt(col) == c) {
            console.log(col)
            document.write("<td style='background-color: yellow;'>", c++, "</td>");
          } else {

            document.write("<td>", c++, "</td>");
          }


        }
        document.write("</tr>");

      }
      document.write("</table>");

    }
  </script>

</body>

</html>

about 4 years ago · Juan Pablo Isaza Relatório

0

set background of all td nth possition

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="7.js"></script>
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="text1">
    <input type="text" name="" id="text2">

<label for="color">Which cell to color</label>
<input type="text" name="" id="color">
    <input type="button" value="Generate" onclick="h()">
    <br>

<!--javascript code-->
<script>
function h(){
var a=document.getElementById("text1").value;
var b=document.getElementById("text2").value;
var col=document.getElementById("color").value;
var g=parseInt(col);
document.write("<table border='1'>");
var c=1;
for(i=0;i<a;i++){
    document.write("<tr>");
    for(j=0;j<b;j++){
        var background = '';
        if(g == j){
            background = 'style="background-color:red"';
        }
        document.write("<td "+background+">",c++,"</td>");
    }
    document.write("</tr>");
}
document.write("</table>");

}
</script>

</body>
</html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda