Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JavaScript : Uncaught ReferenceError

Guest
Feb 26, 2013 Feb 26, 2013

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.

TOPICS
Advanced
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Feb 26, 2013 Feb 26, 2013

Check your quotes around Hello World...

Jim Leichliter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 26, 2013 Feb 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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Feb 26, 2013 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 26, 2013 Feb 26, 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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 26, 2013 Feb 26, 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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Feb 26, 2013 Feb 26, 2013

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 27, 2013 Feb 27, 2013
LATEST

Hey Jim,

No sorry for the confusion, what i said was " and it *feels *like the CP

program is inside of an iframe or something" but its not i checked.. but

ill try this today and hope for the best.

thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources