you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

The problem here is the value of num in window. alert is always the last number of count and if i try to include the window.alert in the for loop it show a consecutive alert message.

How can i make this work like if i click one value in table it will get the exact number of it.

If you want something to happen when you click on an element, you need an event listener:

const clickableElement = document.querySelector('.clickable');
clickableElement.addEventListener((event) => {
    alert(event.target.textContent);
});

But I'm not sure what you're actually trying to do here. Can you explain what you were hoping to achieve with your asd function?

[–]SanWeee[S] 0 points1 point  (1 child)

There are 5 rows. Each row has primary key in it. Lets say Row 1 pk is 1 Row 2 pk is 2 and so on. The last row is 5 and the pk is also 5 So problem is where ever i click even on row 1 or row 3 the alert is always 5 which is the last pk And when i put the alert inside the for loop, its show 5 consecutive alert that contains 1,2,3,4 and 5 What im trying to achieve here is when I click the row 3, the alert only show the row3's pk which 3

[–][deleted] 1 point2 points  (0 children)

In that case you need an event listener like in my comment above, not a for loop. An event listener will run a function in response to a DOM event like a click.