simo9900 simo9900 - 1 year ago 108
Ajax Question

exctracting a variable from a jquery method

I want to extract the variable

from the
method and using it outside this method, but when I try an
on this variable it's empty.

jQuery(document).ready(function() {
var choix = $('#choixaide').val();
var choix_sous_theme1 = $('#choix_sous_theme1aide').val();

$('textarea.mention1').mentionsInput('val', function(text) {
var response = text;


Thanks for your help.

Answer Source

As you have it now, response is only available within the scope of your mentionsInput method, but not outside of it.

Additionally, when running your code, I see the following error:

Uncaught TypeError: $(...).mentionsInput is not a function"...

Are you sure you've properly loaded the jquery.mentionsInput UI component? You'll need to solve for this error first, if you are also encountering this.

Then, you'll need to declare the variable response prior to and outside of your mentionsInput method, and then set it within mentionsInput. response should then be available in the same scope as your alert call.

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