SoftwareSavant
SoftwareSavant

Reputation: 9747

Table Row... Show an alert onClick

Hello I have a simple HTML table with several rows. I want to alert the user with a message when they click on a particular row. Here is what I tried to get this to work...

        <tr onClick="alert(some Message)">
            <td>${o.hospitalId}</td>

            <td>${o.name}</td>

            <td>${o.address}</td>
        </tr>

However, that is not working. Am I missing some HTML basics here?

Upvotes: 0

Views: 5889

Answers (4)

Anil Meenugu
Anil Meenugu

Reputation: 1431

Some Message should be single quotes ' text ' reason behind your alert not working

<table>
    <tr>
       <td onclick="alert('You are clicking on the cell EXAMPLE')"> Data </td>
    </tr>
  </table>

Upvotes: 0

vikhyat tandon
vikhyat tandon

Reputation: 1

add these 'some message' and then it will work fine

    <tr onClick="alert('some Message')">

        <td>${o.hospitalId}</td>
        <td>${o.name}</td>
        <td>${o.address}</td>
    </tr>

Upvotes: 0

ghoot
ghoot

Reputation: 66

Code seems to be good, of course if you want display literary 'some Message' text it must be between ' and ', like in lante's example. If it won't work still, you can have javascript disabled in browser settings.

Upvotes: 1

lante
lante

Reputation: 7336

seems to be ok, but try:

<tr onclick="javascript:alert('something');">

or try jquery:

$("tr").click(function () { alert("something"); });

Upvotes: 1

Related Questions