Skip to main content
February 26, 2013
Question

JavaScript : Uncaught ReferenceError

  • February 26, 2013
  • 1 reply
  • 1874 views

ok, so when we put the folowing into the top of moodle LMS on theplayer.php page:

                    <script type="text/Javascript">

                       function myFunction(){

                               alert('Hello world");

                       }

                     </script>


and we setup a button to fire this script :

"myFunction();"

we get an error :

Uncaught ReferenceError: myFunction is not defined

is there something that we are doing wrong here ? all the tutorials that we have read says we should be able to do this quite simply with capivate 6.

its on a webserver(dreamhost) and still not working.

This topic has been closed for replies.

1 reply

Brainiac
February 26, 2013

Check your quotes around Hello World...

Jim Leichliter

February 26, 2013

I have edited that to fix it .. turns out I had it wrong in here.. it was single quote in the CP file. still not working am I wrong in what im thinking ? should it work this way ?

Brainiac
February 27, 2013

Thanks for the response Jim,

The problem with that solution (which I tried and works) is that I'm trying to access some elements from within the DOM, and it feels like the CP program is inside of an iframe or something ?..

at any rate is there a way to access functions from outside the CP realm? I see lots of examples however I cant get it to work.. is there a switch that i need to throw in CP to make it work or something .. its very frustrating.

perhaps even just do something simple like return the innerHTML of a DOM element ?


Yes, you can access functions from outside the Cp realm.  So if I understand your correctly, you have Cp loading in an iframe and you want to access DOM elements in the parent?  Take a look here:

http://stackoverflow.com/questions/935127/how-to-access-parent-iframe-from-javascript

Once you have a JS reference to the parent window, you're free to get crazy!