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 ?

February 26, 2013

No, you're not wrong in thinking that it should work that way... but where you put your JS functions depends on what you're trying to do.

Instead of altering the LMS (Moodle), you probably want to include your JS functions inside the standard.js file that Captivate outputs.  You can call those functions from inside Captivate just the same as if the function was defined in the php or html page.  Using the standard.js file gives you two distinct advantages:

1.  It gives you the flexibility to alter your JS funcitons from course to course... and apply consistency from course to course.

2.  If you modify the standard.js file in your Captivate installation directory, you can have these JS functions available during testing... and the file gets automatically get coped to the publishing output folder when you publish.  No manual copy/paste.

Jim Leichliter


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 ?