How to put a text box in javascript

Asked

Viewed 2,819 times

2

I would like to know how to put a text (input) box in javascript, to be more specific, within a given cell of a table (generated through an array). From now on... J.G..

<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
</head>
<body onKeyDown="pegadirecao(event.keyCode);">
<div id=principal></div>
<script>
tabuleiro="<table align=center border=1>";
	for(x=0;x<2;x++)
	{ tabuleiro+="<tr>";
		for(y=0;y<5;y++)
		{ tabuleiro+="<td id=td"+x+"_"+y+" style='width:70px; height:70px;'></td>";
		}
		tabuleiro+="</tr>";
	}
tabuleiro+="</table>";
document.getElementById('principal').innerHTML=tabuleiro;
 </script>
</html>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
</head>
<body onKeyDown="pegadirecao(event.keyCode);">
<div id=principal></div>
<script>

  • Enter the code of that matrix.

  • rray, I just put the code!

  • 2

    Always put the code and the description of the problem or doubt so it is easy for the staff to help you :)

1 answer

1


Here’s an example of what you’re trying to do:

<!DOCTYPE html>
<html>
<head>
<style>
table, td {
    border: 1px solid black;
}
</style>
</head>
<body>


<table id="myTable">
  <tr>
    <td>cell 1</td>
    <td>cell 2</td>
  </tr>
  <tr>
    <td>cell 3</td>
    <td>cell 4</td>
  </tr>
</table>
<br> 

<button onclick="myFunction()">Alterar celula 0,0</button>

<script>
function myFunction() {
    var x = document.getElementById("myTable").rows[0].cells[0];
    x.innerHTML = "<input type='text' >";
}
</script>

  • Eduardo Binotto, man, thank you so much!

  • You’re welcome @J.Gaidzinski, I’m happy to help. If you can mark my answer as the best I appreciate it. Thank you.

Browser other questions tagged

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