1

Okay, so I recently had an issue I needed to resolve in old code (Code that I haven't written). I have got so far with fixing this and hit another wall. I suspect there is an issue within a method in the code so I need to see the code in this method to determine if that is the issue as I'm debugging completely manually.

Issue is, is that I can't find the definition of the method. It is no where to be found inside any of the files within the same directory. Does anyone have any idea how I may go about looking for a method. It is clearly somewhere as the application wouldn't work at all without it.

<div class="col-md-6" id="Invoice"><img src="<?php echo asset_url(); ?>images/loading.gif" width="15px" onload="AlertTest('Invoice','<?php echo $FI; ?>')"></div>

It is the AlertTest() I am looking for.

NOTE: highlighting and selecting 'Go to definition' in VS does NOT work because there is 'no definition found for AlertTest()' :/

Nico Haase
  • 11,420
  • 35
  • 43
  • 69
  • 3
    `AlertTest` is a JS function. You can simply run the code in your browser and call that function in the JS console – Nico Haase Feb 21 '22 at 13:24
  • @NicoHaase Okay. So it's a pre-existing method not a custom defined one? – Nathan Gillespie Feb 21 '22 at 13:26
  • @NicoHaase I can't seem to find any documentation on this function. Do you have any? – Nathan Gillespie Feb 21 '22 at 13:29
  • Who said that this was "pre-existing"? Maybe https://stackoverflow.com/questions/9828876/find-javascript-function-definition-in-chrome could help? – Nico Haase Feb 21 '22 at 13:34
  • @NathanGillespie open the browser console, use the arrow, select the element, on the right click on "Event Listeners" and then expand the item "click", there you find a list of all the functions executed on the click with the file that defined them – Christian Vincenzo Traina Feb 21 '22 at 13:35

1 Answers1

0

This AlertTest function is a Javascript function, not a php function. Your browser calls it in Javascript. The php code you showed us simply writes the function call into the browser web page. It does not run the function.

AlertTest() is not a standard function provided by the browser's Javascript engine. That means it is defined somewhere within the Javascript code your web site sends to the browser with each page, or in code your page loads from a content delivery network or someplace else.

Here's how to find it.

  1. Display the page.
  2. Right-click on that Invoice element and choose Inspect. You'll see the HTML of the page in your browser's devtools panel.
  3. Look for the call to AlertTest(). You can search inside the HTML using ctrl-f.
  4. When you find it, right-click on it and choose Reveal In Sidebar. The devtools will highlight the file where the function is defined.
  5. Click on the highlighted file name in the sidebar, and voilà.

You'll then have to hunt down the file in your source code. If you right click on the file name in the sidebar, you can choose Open in New Window or Copy Link Address.

Pro tip: Every hour you spend figuring out how to use the browser's devtools feature will save you tens of hours when you're figuring out how web pages work.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • Thanks for the detailed response! I have managed to find the file after a little bit of manual searching. I wish I did this before, but now I know! I've found the issue now and have managed to fix it so the invoices are loading properly now. – Nathan Gillespie Feb 21 '22 at 14:06
  • Just to add to this however, I'm trying to find the file path in your suggested way and I can't find the AlertTest() function in the HTML... Even just searching for 'Alert' doesn't show anywhere. Can js script be picked up in dev tools? Hidden perhaps? – Nathan Gillespie Feb 21 '22 at 14:11