Expand my Community achievements bar.

SOLVED

Additional JavaScript file

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 5

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 .

View solution in original post

4 Replies

Avatar

Correct answer by
Level 5

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 .

Avatar

Level 10

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

Avatar

Level 9
In your jsp/html code add the following before calling the function. <cq:includeClientLib js="jquerysamples" />

This should fix your issue.

Avatar

Level 2

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!