Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get dropdown changed value from in jquery to another function

This is my code

$(function(){
    $('#dropdown_name').change(function(){
        var V = $('#dropdown_name').val();
        var T = $('#dropdown_name :selected').text();
    });
});

I want to send V and T's value below function

function xyz()
{
    a = V;
    b = T;
    alert(a);
    alert(b);
} 

In Function xyz, I have to call many function so I don't want, it take as parameter of xyz function. So how can I get data in another way when I will select a dropdown then it will display alert(a and b) that value and text of dropdown.

How to solve it, please any suggestion.

like image 959
MD. ABDUL Halim Avatar asked Dec 02 '25 12:12

MD. ABDUL Halim


1 Answers

You can use global variables instead:

function xyz()
{
    a = window.V;
    b = window.T;
    alert(a);
    alert(b);
} 

You will call the function like so:

$(function(){
    $('#dropdown_name').change(function(){
    window.V = $('#dropdown_name').val();
    window.T = $('#dropdown_name :selected').text();
    });
});
like image 100
jjnguy Avatar answered Dec 04 '25 06:12

jjnguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!