Dashboards & Visualizations

calling a javascript function through application.js file

smolcj
Builder

hi all,
created a application.js file with following content and saved in the location myapp/appserver/static

        <script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>

and i used <html> tag and tried to call this function

<a href="#" onclick="toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>

This is foo
'
but the function is not loading
please help
thank you

Tags (1)
0 Karma

joelzyla
Explorer

You don't need script tags when using the application.js file. It is already in a .js file. Script tags would be used if you were embedding the script within some html.

You also don't need html tags in a .js file...

The application.js is called from HTML else ware, and is automatically loaded in your app.

So, simply put your code in the application.js file:

function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}

Drainy
Champion

The code you've posted at the top is written as if it is contained within a HTML page and not a JS file. This is moving more into the boundaries of a site like stackoverflow or something similar for javascript troubles. If this relates to the other post about making modules visible or not then make sure you've understood what has been pasted.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...