2

Strangely onclick of <tr> is not working in my case when I put it on JSFiddle http://jsfiddle.net/dad5m5vb/

This is the HTML:

<form id="form_city" action="">
    <table width="100%" border="1" cellspacing="0" cellpadding="0">
        <tr>
            <th>City Id</th>
            <th>City Name</th>
        </tr>
        <tr id="row1" onclick="rowClicked(this);">
            <td>1</td>
            <td>New York</td>
        </tr>
        <tr id="row2" onclick="rowClicked(this);">
            <td>2</td>
            <td>Los Angeles</td>
        </tr>
        <tr id="row2" onclick="rowClicked(this);">
            <td>3</td>
            <td>Chicago</td>
        </tr>
    </table>
</form>

This is the JavaScript:

function rowClicked(clickedRow) {
    alert(clickedRow);
}

On clicking on any row (except the header), the javascript function should be called. But I am not getting the alert from the javascript function. Why?

ChumboChappati
  • 1,442
  • 4
  • 18
  • 38
  • Here: http://jsfiddle.net/dad5m5vb/1/ - Your function needs to be global, but you've used JSFiddle's default `onload` wrap (on the left under Frameworks & Extensions you need to put it in `` or ``). – nnnnnn May 20 '15 at 22:18

1 Answers1

3

You must change the JSFiddle onLoad to no wrap - in <head> (http://prntscr.com/77j08q) so that the code loads in the <head> instead of loading when the DOM loads.

Firedrake969
  • 763
  • 8
  • 22