Additional JavaScript file | Community
Skip to main content
maximilian_queh
Level 2
October 16, 2015
Solved

Additional JavaScript file

  • October 16, 2015
  • 4 replies
  • 1564 views

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.
Best answer by vdhim23

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

vdhim23Accepted solution
Level 5
October 16, 2015

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 .

smacdonald2008
Level 10
October 16, 2015

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

Community Advisor
October 16, 2015
In your jsp/html code add the following before calling the function. <cq:includeClientLib js="jquerysamples" />

This should fix your issue.

maximilian_queh
Level 2
October 16, 2015

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!