How to put a text box in javascript

2

I would like to know how to put a javascript input box, to be more specific, within a given cell of a table (generated through an array). Right now ... 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>
    
asked by anonymous 21.09.2015 / 18:56

1 answer

1

Here's an example of what you're wanting 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>

    
21.09.2015 / 19:04