Vignesh Pichamani Vignesh Pichamani -5 years ago 128
jQuery Question

Call Variable Function from External JS File

I was trying to call the function outside js file, but that function is declared in variable, something like this below

external.js is the third party library which i shouldn't edit

var submit_clicked={
cart_submit: function() {
alert("yes variable function is have scope outside");


In my side i call internal javascript something like

jQuery(function() {

it denotes

Reference Error: submit_clicked is not defined

not sure how to overcome this issue. Can anyone suggest some ideas will be great :)

Here is my fiddle.

FYI: I call my script next to the external js but still that scope is not available.

Answer Source

The problem lies in the external.js file. Declare the variable outside the jquery() handler and that should solve your issue!

If the external file is non-editable, then you cannot access the variable function due to its scope which is local (what you need is a global variable).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download