Support » Plugins » Hacks » Custom Javascript Functions not defined in wordpress admin

  • Resolved nickpower

    (@nickpower)


    Hi There,

    I have enqueued my own Javascript file so that it is loaded when ever a page is edited within the wordpress admin.

    The file is loaded in fine and I can create jQuery code that actions absolutely fine. However, I have a problem when I wish to create my own very very simple javascript functions.

    Like:

    function blah(theid){alert('This Works Nicely!');}

    Any functions that I define and attempt to call using something like

    <a href="#" class="delete_pimg" id="pimg_1" onclick="blah(1);return false;">Does this work?</a>

    Come back on the console “blah is not defined”

    Please Help!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Did you look to see when everything is loading? If your function is defined AFTER your onclick call then it would return as undefined.

    It’s being loaded in the head section. After the globals.js.

    It’s really bizarre (and annoying)!

    I solved this problem by including the function code using inline javascript.

    <script type="text/javascript">
    function blah(theid){alert('This Works Nicely!');}
    </script>
    
    <a href="#" class="delete_pimg" id="pimg_1" onclick="blah(1);return false;">Does this work?</a>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Javascript Functions not defined in wordpress admin’ is closed to new replies.