NaN
NaN

Reputation: 1306

How can I get the value from one function into document ready?

I have 2 files. File one calls a function in file 2. I can alert the value passed into file 2 if that function is outside of the document ready function. I need that value inside of document ready. Is there a way to do this?

file 1:

setId(1);

file 2

function setId(v){
  alert(v); // This works
}

If I place the function within the document ready function, I can no longer access the value passed in to it.

Upvotes: 0

Views: 69

Answers (1)

Bharath
Bharath

Reputation: 807

use the following code define setId function

window.setId = function(v){
alert(v);
}

EDIT: Method 2 from Nick

window.myapp = window.myapp || {};

myapp.setId = function(v){
alert(v);
}

to call the setId function

myapp.setId("test");

Upvotes: 1

Related Questions