HOME ➔ SUPPORT ➔ Community ➔ General CourseLab issues ... how to execute javascript function
how to execute javascript function
  View type:
hello

I am trying to arrange to execute a piece ajax code when a question is submited and the correct response is given. I used the ONSUCCESS event with JAVASCRIPT

JAVASCRIPT(javascript=functionName(arg1))

This is not working for me. Is this the correct way to arrange for selt-tailored function to execute. The
function is placed in module.js

thanksfor help
jamemeo
 
Instant thought is .... the js runs in the page courselab uses to display the content... The page needs to be told to use the js when you invoke it.
For example to use this particular script in a page (tjpzoom) I have this in the header...
script type="text/javascript" src="tjpzoom.js" /script note that >'s ommitted)
So when in the body I invoke onmouseover="TJPzoom(this) it works, leave out the pointer in the header and nothing happens.
If you add this to the start.html file I think Courselab should be able to use the script...

 
 
Also you will probably need to add pointers to the ajax support libraries or code otherwise your script might not run.
AND you'll need to confirm that your ajax will run properly in a page which doesn't have a doctype formally declared. The page type is an MS vml schema type that might raise issues.
 
 
 
Hello Nick

Thanks for your input. I am familiar with the basics. This is my problem:

I have a function which I placed in the mojule.js (a courselab file). Whenever I submit a question I want to
call that function with a parameter.

Question:

Which acton is appropriate and plase give an small example.

*note* I have tried the JAVASCRIPT but has not worked for me. May I am using wrong. That why ask for a simple example

thanks much
 
 
 
 
If you want the js event to happen if the answer is correct then onsucsess should be right for the event. So a correct answer invokes the js event.
Courselab does seem to be quite sensitive to the way you write the js. The whole needs to be inside ' single quotes' .
Makes me wonder if it is just a syntax problem in your js code, that is the way that Courselab rewrites it when it renders the page, not the code itself.
Can you run the module using firebug or java console to get a handle on what is actually happening when it's invoked?
I'd still point out that some ajax isn't going to function as expected in the page DOM where the page is non-declared DTD, MS VML's can be problematic.
 
 
 
 
 
On this syntax biz... The whole script you add to the javascript tage needs to be wrapped in ' ' s IF the code has another set inside these then it will treat the last as the end of the code section and the script between them is ignored.
So where any internal ' ' s are used they need to be wrapped in " " s (I think??). I'd need to experiment to see but I'm a bit snowed under at the moment but if I get a block of time free I'll have a look and see.
 
 
 
 
 
 
Hello Nick

I tried the ajax script in Mozilla as you suggested and it worked. You had
mentioned somrthing about

non-declared DTD, MS VML's can be problematic.

I am not clear on this point except to say the code is not working in IE6 or IE7.

Any idea how to get around this obstacle. You help , as always, is greatly appreciated

thanks much
james
 
 
 
 
 
 
 
OK So what is the script and what is it trying to do?
Is the module running as a stand alone or within the framework of a CMS or LMS.
Is the module accessed online or just on th local PC.
If you save the module or a dummy with this ajax scripting in does the module work on firefox and fail on IE?

For general interest if anyone else is looking at this strand AJAX is:
Asynchronous JavaScript and XML and is a group of interrelated web development techniques used for creating interactive web applications. Ajax allows web applications to retrieve data from a server asynchronously in the background without interfering with the display or behavior of the existing page.
Data is retrieved using the XMLHttpRequest object or through Remote Scripting in browsers that do not support it.

So we already have the potential VML and undeclared DTD, we also may have calls from JS to another server. We also have to contend with the vagaries of IE :( which is probably where the real problem is.
There may be a really aimple solution from the large number of web work arounds needed to use these browsers.
 
 
 
 
 
 
 
 
Courselab uses the XMLHttpRequest object, notice the test page that checks you have MSXML ActiveX control, Mozilla has the function built in.
So the problem is possibly related to the remote scripting side in which case explorers set up might be a problem.
If the script isn't written to be cross browser compliant then you can get problems.
 
 
 
 
 
 
 
 
 
Hello Nick

I appreciate your help. I got the script working. Thanks alot.

I am going to post a question about
disabling/enabling the NEXT BUTTON on
a slide in separate thread. As always
your comment would be apprciated.

james
regards
Subject:
Message options
No additional options