Hi i have a question a tryaing to create Amount calculator in jQuery, AJAX and jQuery UI. But i have a problem, i get all importat values from slider, select box. Bud i really don't know how can a get this value to global. I get value only in each function but when i want get this value out of function this value in variable does not exist. 

```
$(function() {
    //1st slider for get amount
    $("#amount").slider({
        range: "min",
        value: 0,
        min: 0,
        max: 10000,
        slide: function (e, ui) {
            $("#amount_show").val(ui.value);
            amount = ui.value;
            }
    });
    $("#amount_show").val($("#amount").slider("value"));

    //2nd slider for get values years
    $("#years").slider({
        range: "min",
        value:1,
        min:1,
        max:20,
        step:1,
        slide: function (e, ui) {
            $("#years_show").val(ui.value);
            years = ui.value;
            }
    });
    $("#years_show").val($("#years").slider("value"));

    //AJAX for loading values from xml
    $.get("irate.xml", function(xml) {
            $(xml).find('country').each(function() {

                var select = $('#country'),
                    id = $(this).attr('id'),
                    name = $(this).find('name').text(),
                    irate = $(this).find('irate').text(),
                    currency = $(this).find('currency').text();

                select.append("<option value='"+irate+"'>"+name+"</option>");
        });
    });

    //get irate value from dropbox
    $("#country").change(function() {
        var irate_select = "";
        $("#country option:selected").each(function () {
            irate_select += $(this).val() + " ";
            });
            irate = irate_select;
        });
});

```

I need calculate with amount, years and irate.

Thank for your advice.
['https://Stackoverflow.com/questions/6624921', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/896953/']
AndyL's answer should be correct.

If you declare the variables you need available in another function outside of your function, and then set their values in one function, they should be available with those values to another function.

```
// outside your function!!
var amount,
    years,
    irate;

// in your function somewhere!!
amount = someCalculation();
years = someOtherCalculation();

```

These values will be available in every other function because they are declared as members of the global namespace.
Try using jquery's data() object;

```
$(function(){
...

slide: function (e, ui) {
    $("#amount_show").val(ui.value);
    amount = ui.value;

    // Add to data() object here
    $('#amount').data('amount',amount);
}

// reference it elsewhere in your script like such:
console.log($('#amount').data('amount'));

```