0

Hai,

I have one HTML page with Javascript functions included in it. In that HTML page, I have a table with 2 rows and 2 columns. Also I have an array with 4 values. What I need is, when the user clicks on one table cell, a value from the array should be displayed inside that cell. Can any one post some sample code here?

Thanks.

0

2 Answers 2

2

[See it in action]

var values = [1,2,3,4];

var table = document.getElementById('tablet');

// watch for clicks on the table
table.onclick = function(e) {

  // get the element that was clicked
  e = e || window.event;
  var el = e.target || e.srcElement;

  // set it's content to a value from the array
  if (el.nodeName == "TD") {
    el.innerHTML = values.shift();
  }

};
​
Sign up to request clarification or add additional context in comments.

1 Comment

This is great. I expected this one...Thanks galambalazs.
0

Here is some sample code,

 <script type="text/javascript">
function changeText()
{
    alert('');
    document.getElementById('row').innerHTML = 'some text';
}
</script>

<table border = '1'>
<tr><td id='row' onClick='changeText()'> </td>
</tr>
</table>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.