img

Dear gurus, there is a sign when you click on a cell so that the value ( innerHTML ) fits into the form ( <input type="text" id="идячСйки" ΠΈΠ»ΠΈ name="идячСйки"> ).

I have a column id ( <td id="ΠΈΠ΄"> ) and an index <tr> : ( row.sectionRowIndex ). There is a click handler, tell me the code to calculate the value and write it to the form. Thank you very much in advance.

The table is generated by the php principle and you can set the id and <tr> if this somehow helps.

Regards, Oleg.

Everything turned out to be much simpler:

 document.getElementById(ΠΈΠ΄ Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹).rows[ΠΈΠ΄ td].cells[ΠΈΠ΄ tr].innerText 

Good luck to all.

  • Only use innerHTML, because under certain conditions innerText may not work - deivan_
  • Thank you, and for what if not a secret? And in general, javascript is not very strong, please tell me how correct this construct is: document.getElementById ('atip'). Value = document.getElementById (tableId) .rows [row.sectionRowIndex] .cells ['tip']. InnerHTML. substr (0, 1); on most browsers (ie7 +, ff, chrome, opera) works like rules .... - ferrari
  • IE6-7 and firefox. Innertext do not favor ... - deivan_

1 answer 1

This is how you can get all td in the row you clicked on (the elements td will be in the elements array), here you can run a working example . all you have to do is to loop through the array and transfer the data to the fields.

 var table = document.getElementById("tstTB"); table.onclick = function (e){ var target = event.srcElement || e.target, elements; var parent = target.parentNode; while(parent.tagName != "TR" && parent ) { parent = parent.parentNode; } elements = parent.getElementsByTagName("td");// всС элСмСнты td };