Skip to main content
maximilian_queh
Level 2
Oct 16, 2015 2:26 AM UTC
Solved

Additional JavaScript file

Hello,

in my apps folder  I have a project "myproject" and in this folder there is a folderstructure "components/clientlibs"

./components/clientlibs/js.txt looks like this:

#base=js
mqbehaviour.js
jquery-2.1.1.js

and mqbehaviour.js contains the following code:

function testFunction() { alert('Hello from testFunction'); }

In my page I have the following button:

<form action="button.htm"> <div> <button name="Click me" type="button" value="Supprise" onclick="testFunction();"> <p> <b>What will happen?</b> </p> </button> </div> </form>

If I press the button, nothing happens - and in Firebug I get the exception: testFunction does not exist

Has anyone any idea what I am doing wrong. I thought if I add the file in js.txt than it is alos loaded and therefore the function "testFunction" should be available.

Thanks for any hint in this direction.

Max

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
vdhim23Accepted solution
Level 5
Oct 16, 2015 2:26 AM UTC

maximilian.quehenberger wrote...

Hello,

in my apps folder  I have a project "myproject" and in this folder there is a folderstructure "components/clientlibs"

./components/clientlibs/js.txt looks like this:

#base=js
mqbehaviour.js
jquery-2.1.1.js

and mqbehaviour.js contains the following code:

  1. function testFunction() {
  2. alert('Hello from testFunction');
  3. }

In my page I have the following button:

 
  1. <form action="button.htm">
  2. <div>
  3. <button name="Click me" type="button"
  4. value="Supprise" onclick="testFunction();">
  5. <p>
  6. <b>What will happen?</b>
  7. </p>
  8. </button>
  9. </div>
  10. </form>

If I press the button, nothing happens - and in Firebug I get the exception: testFunction does not exist

Has anyone any idea what I am doing wrong. I thought if I add the file in js.txt than it is alos loaded and therefore the function "testFunction" should be available.

Thanks for any hint in this direction.

Max

 

 

Do you have you js files inside js folder under clientlibs. As #base js will look your javascripts files under js folder inside clientlibs. clientlbs -> js -> file.js .

4 replies

maximilian_queh
Level 2
Oct 16, 2015 2:26 AM UTC

Hi,

thanks for the response. The first lines of my JSP look like this:

<%@include file="/libs/foundation/global.jsp"%> <cq:includeClientLib categories="jquerysamples" />

and css and jquery is included, but my javascript file mqbehaviour.js is not included - and I don't understand why.

Maybe someone has another hint concerning this issue

Thanks a lot!

Translate
Community Advisor
Oct 16, 2015 2:26 AM UTC
In your jsp/html code add the following before calling the function. <cq:includeClientLib js="jquerysamples" />

This should fix your issue.

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:26 AM UTC

try putting all files in the same clientlibs folder. That is, flatten the clientlibs folder. I have never had any issues by doing so. 

Translate
vdhim23Accepted solution
Level 5
Oct 16, 2015 2:26 AM UTC

maximilian.quehenberger wrote...

Hello,

in my apps folder  I have a project "myproject" and in this folder there is a folderstructure "components/clientlibs"

./components/clientlibs/js.txt looks like this:

#base=js
mqbehaviour.js
jquery-2.1.1.js

and mqbehaviour.js contains the following code:

  1. function testFunction() {
  2. alert('Hello from testFunction');
  3. }

In my page I have the following button:

 
  1. <form action="button.htm">
  2. <div>
  3. <button name="Click me" type="button"
  4. value="Supprise" onclick="testFunction();">
  5. <p>
  6. <b>What will happen?</b>
  7. </p>
  8. </button>
  9. </div>
  10. </form>

If I press the button, nothing happens - and in Firebug I get the exception: testFunction does not exist

Has anyone any idea what I am doing wrong. I thought if I add the file in js.txt than it is alos loaded and therefore the function "testFunction" should be available.

Thanks for any hint in this direction.

Max

 

 

Do you have you js files inside js folder under clientlibs. As #base js will look your javascripts files under js folder inside clientlibs. clientlbs -> js -> file.js .

Translate