Skip to content Skip to sidebar Skip to footer

Jquery Passing A Parameter Between Functions

Hey i would to pass a parameter from a function in jquery, but i cant get it to work. what am I doing wrong? I would like to pass 'name' from the click function to the dialog block

Solution 1:

Because you failed to define name with the var keyword, it is already accessible by any other code on the page.

Other than this special case, variables have function scope, so define a var name... at the level higher than both functions that require access to it.

Why you should use 'var'


Solution 2:

just right after

 $(function () {

put var name ;

explanation :

create the variable in the global scope , and then we you assign it from a function it will be accessible out side it ..

you are wrapping the variable as a text ! with the qouts around it , this means that this is some text not a variable you should chnage the line to title:

'<%=GetUserName(' + name + ')%>'

this line will mean treat any thing between the quotes as text and when you come to name just get it value and append it to the text and then complete the text ..

edit : wait a second here , you cant pass javascript variable to function on the server side , except though ajax , but not like this .. you should use post or get to send it to the server and then grap it from there and fire the function and catch back the result !


Post a Comment for "Jquery Passing A Parameter Between Functions"