3

I have a page which loads a lot of JavaScript files. Somewhere in the files, an onchange handler is added to an inputfield A.

When a value is added into inputfield A, inputfield B is automatically filled in with another value (depending on the value of A).

The sheer number of files and the names of the inputfields ('code', 'key') make it hard to use grep to find where the onchange is defined.

I've tried using

  • Opera Dragonfly
  • Firefox Firebug
  • Google Chrome Developer Tools

but I can't seem to find out how to get them to show me where I can find the onchange function that gets called.

Anyone got an idea?

Konerak
  • 39,272
  • 12
  • 98
  • 118
  • 1
    Do you know that something is assigning to the 'onchange' property: it may be using addEventListener or equivalent (which is a much more flexible interface for setting event handlers, but bypasses the "onxxx" properties) – Colin Fine May 18 '11 at 13:17
  • That is possible too - can you include how to find these too in your answer? :) – Konerak May 18 '11 at 13:43

5 Answers5

1

Chrome has build in developer tools that allow you to inspect an element and see any event listeners attached to it.

Google chrome developer tools really are amazing. http://code.google.com/chrome/devtools/docs/elements.html

herostwist
  • 3,778
  • 1
  • 26
  • 34
  • The "EventListeners" tab indeed shows a changelistener, a focus and a keydown, but it shows an "anonymous function" with no hint at where to find the actual function. – Konerak May 18 '11 at 13:40
  • Try going to the script tab and adding an 'event listener breakpoint' for the event your looking for, triggering that event, and then use the 'step into next function' button to drill down to find your anonymous function. you may have to click that button a lot. – herostwist May 18 '11 at 14:45
  • I'm sorry, I can't find how to add that "Event Listener Breakpoint". I don't know which function it is? – Konerak May 18 '11 at 14:53
1

you can see the jquery expression in firebug DOM inspector using firequery in firefox https://addons.mozilla.org/en-us/firefox/addon/firequery/

Rajani Karuturi
  • 3,450
  • 3
  • 27
  • 40
  • +1 This indeed shows me the two functions that get called! I'd still like to know **where** they get added, but atleast now I can see what they are doing. Thanks! – Konerak May 18 '11 at 14:11
0

I had the same issue and I used Google Chrome's dev tool and it helped. Follow the steps below:

  1. Select the event listener breakpoint

  2. Select control checkbox

  3. Select onChange this will pause on the onChange function in your code

iamdanchiv
  • 4,052
  • 4
  • 37
  • 42
0

You can use Firebug to set a breakpoint when a particular HTML element has an attribute change:

http://getfirebug.com/doc/breakpoints/demo.html#html

You could try selecting the second element you've described (that gets filled in) and see if that works for you.

James
  • 13,092
  • 1
  • 17
  • 19
  • Nice thinking, but alas: the attribute never changes once the page is loaded, and your link shows "Breakpoints on Event Handlers: This feature not yet implemented". – Konerak May 18 '11 at 13:41
0

Visual Events allows you to inspect the bound events without editing your code:

http://www.sprymedia.co.uk/article/Visual+Event

George Cummins
  • 28,485
  • 8
  • 71
  • 90