how to return value outside change function using Jquery
<p>This is the code for a Jquery button event, it checks each tr and each td, and if it changed, it goes further and returns some attribute values into hidden controls,</p>

<pre><code>function SetUpdateOnchange() 
{
$('.sd-flex-grid tbody tr').each(function(intChangedRowNo) {
    //alert('test row');
    $(this).children('td').find(':input,textarea').change(function() {
      //  alert('test');
        var strKeyField = '';
        var strKeyValue = '';
        var strKeyType = '';
        strActField ='';
        strActValue ='';
        strActType ='';
        var strUpdateRows = new String($('#sd-hidden-updaterowsno').val());
        var re = new RegExp(intChangedRowNo + "~+");
        if (strUpdateRows.match(re) == null) {
            $('#sd-hidden-updaterowsno').val($('#sd-hidden-updaterowsno').val() + intChangedRowNo + "~");
            var rowCount = 0;

            $('.sd-flex-grid tbody tr').each(function() {
                if (rowCount == intChangedRowNo) {
                    $(this).children('td').each(function(i) {

                        if ($(this).attr('primarykey') == 'primarykey') {
                            if ($(this).attr('fieldname') != "") {
                                strKeyField = strKeyField + $(this).attr('fieldname') + "|";
                                if ($(this).attr('datatype') == "") {

                                    if (typeof $(this).attr('format') != 'undefined') {
                                        strKeyValue = strKeyValue + RemoveComma($(this).attr('val')) + "|";
                                    }
                                    else {
                                        strKeyValue = strKeyValue + $(this).attr('val') + "|";
                                    }

                                }
                                else {

                                    if (typeof $(this).attr('format') != 'undefined') {
                                        strKeyValue = strKeyValue + RemoveComma($(this).text()) + "|";
                                    }
                                    else {
                                        strKeyValue = strKeyValue + $(this).text() + "|";

                                    }
                                }
                                strKeyType = strKeyType + $(this).attr('actualtype') + "|";
                            }
                        }


                        else if ($(this).attr('primarykey') == '') {

                            $(this).change(function() {


                                if ($(this).attr('fieldname') != "") {
                                    strActField = strActField + $(this).attr('fieldname') + "|";
                                    if ($(this).attr('datatype') == "") {


                                        if (typeof $(this).attr('format') != 'undefined') {
                                            strActValue = strActValue + RemoveComma($(this).attr('val')) + "|";

                                        }
                                        else {
                                            strActValue = strActValue + $(this).attr('val') + "|";

                                        }

                                    }
                                    else {
                                        $(this).find(" :input").each(function() {


                                            // We are checking the format attribute is available..
                                            if (typeof $(this).attr('format') != 'undefined') {
                                                strActValue = strActValue + RemoveComma($(this).text()) + "|";

                                            }
                                            else {

                                                strActValue = strActValue + $(this).val() + "|";


                                            }


                                        });



                                    }
                                    strActType = strActType + $(this).attr('actualtype') + "|";


                                }

                                //$('#sd-hidden-updaterowscolkey').val($('#sd-hidden-updaterowscolkey').val() + strKeyField + "~");
                                // $('#sd-hidden-updateacttype').val($('#sd-hidden-updateacttype').val() + strActType + "~");
                                // $('#sd-hidden-updateactdata').val($('#sd-hidden-updateactdata').val() + strActValue + "~");
                               //  $('#sd-hidden-updateactfield').val($('#sd-hidden-updateactfield').val() + strActField + "~");


                            });

                        }

                    });

                }
                rowCount = rowCount + 1;


            });
            rowCount = null;

            $('#sd-hidden-updaterowscoltype').val($('#sd-hidden-updaterowscoltype').val() + strKeyType + "~");
            $('#sd-hidden-updaterowscoldata').val($('#sd-hidden-updaterowscoldata').val() + strKeyValue + "~");
            $('#sd-hidden-updaterowscolkey').val($('#sd-hidden-updaterowscolkey').val() + strKeyField + "~");
            $('#sd-hidden-updateacttype').val($('#sd-hidden-updateacttype').val() + strActType + "~");
            $('#sd-hidden-updateactdata').val($('#sd-hidden-updateactdata').val() + strActValue + "~");
            $('#sd-hidden-updateactfield').val($('#sd-hidden-updateactfield').val() + strActField + "~");


        }

        re = null;
    });
});
}
</code></pre>

<p><strong>strKeyValue</strong> is assgined inside the function and used outside. That works fine. Simillarly, I want to access strActvalue outside of the function. It returns the correct value within the function, but when it is used outside, it shows undefined.</p>

<p>How do use a variable outside a function?</p>
