Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason <em>why</em> the <code>onchange</code> doesn't work as it should is because it's not the <em>cell</em> that changes, it's the form element inside. Sure, if you click on a tables contents, the table is clicked, too. That makes sense: you can't open a door <em>inside</em> a house without opening the front door first.<br/> You can, however, go inside a room, cut your hair (fire a change-event on yourself) without changing the room where this event took place. In that respect, it makes sense the change event doesn't fire on the parent cell.</p> <p>The event <em>does</em> traverse the DOM, though, and it <em>does</em> pass the table cell, so you <em>can</em> pick it up there, but not with HTML attributes. (BTW: try to use those as little as possible).</p> <p>Try binding a listener to the entire table in JS. That way, there's only 1 listener that works for all events (it's called event delegation):</p> <pre><code>//assume tbl has id foobar: document.getElementById('foobar').addEventListener('change',function(e) { e = e || window.event; var target = e.target || e.srcElement; var name = target.id || target.getAttribute('name'); alert('the ' + name + ' element changed!'); },false); </code></pre> <p><a href="https://stackoverflow.com/questions/11331203/javascript-how-to-simulate-change-event-in-internet-explorer-delegation">Here's a slightly more complex version of event delegation</a>, which also deals with change events on select elements in IE8. (the change event doesn't bubble in old IE's).</p> <p>A couple of links:</p> <ul> <li>As always: <a href="https://developer.mozilla.org/es/docs/DOM/elemento.addEventListener" rel="nofollow noreferrer">MDN</a></li> <li>An article on <a href="http://www.sitepoint.com/javascript-event-delegation-is-easier-than-you-think/" rel="nofollow noreferrer">How delegation works</a>, and how easy it really is</li> <li>And good ol' quirksmode: <a href="http://www.quirksmode.org/js/events_order.html" rel="nofollow noreferrer">a comprehensive overview on event order/event models</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload