Javascript: Getting fromForm variable value

I’m trying to get the value from the “fromForm” variable but i dont know how can i get this value to use in the onSubmit function

$(window).on('load',function(){
    grecaptcha.render('recaptcha', {
        'sitekey' : '6LcFrN8cAAAAAMr2P3Nkvm7fDFzIykf30QykYlga',
        'callback' : onSubmit,
        'size' : 'invisible'
        });
});

$('form').submit(function (e) {
    e.preventDefault();
    grecaptcha.execute();
    var fromForm = $(this).data('test');
    }
);

function onSubmit(token){
    alert(fromForm);
};