0

Having a jquery file inside the assets folder,and i want to call a function from it in , I used :

<script type="text/javascript" src="${assetPath(src: 'test.js')}">
<g:submitButton class="hr" name="HR Module" onclick="myFunction();"/>

but it is not working ,although if i put this function inside tags in the GSP it works perfectly .

Anything i'm missing ?

Vinay Prajapati
  • 7,199
  • 9
  • 45
  • 86
Sherif
  • 421
  • 3
  • 15

1 Answers1

0

sample image

Suppose in above snapshot from IDE you have to call application.js, then do it like below

<asset:javascript src="application.js"/>

Or if suppose your file is in some subdirectory under assets, then provide relative path. For example, in above snapshot say we have another application.js in scripts folder under assets dir. Then,

<asset:javascript src="scripts/application.js"/>

These are standard tags provided by assets pipeline to access resource.

Last but not least you could similarly access css as well

<asset:stylesheet src="bootstrap.css"/>

Hope it helps!

Vinay Prajapati
  • 7,199
  • 9
  • 45
  • 86
  • i did as shown but , still the function not called !! – Sherif Dec 10 '15 at 12:12
  • seems you are doing something wrong. You should be calling your script before method call. Also, if using chrome, please check for any error on console. The same mentioned above works well in my project. Can you please check in page source whether the script is added properly or not by clicking on script link and also checking for any javascript errors. – Vinay Prajapati Dec 10 '15 at 12:17
  • i'm putting '' in the **head** and i'm calling the function in the **body** – Sherif Dec 10 '15 at 13:41
  • Did you get the issue @Sherif? – Vinay Prajapati Dec 11 '15 at 06:22
  • ya , something wrong in the JQuery code , but all done and working fine .. appreciate it . – Sherif Dec 12 '15 at 23:48