Retrieve value from javascript funcion on client click

I have a function on JS that must execute before the codebehind, but i’m having trouble retrieving it.
It will return a variable that i should use on the codebehind. The function i created is this one:

            <script type="text/javascript" >
                function returnHash() {
                    var checkout = new DirectCheckout('086F7D02A071267FEBF102EB759D9845B8B3333DFA65BC45B807F41A8525AD8D'); /* Em sandbox utilizar o construtor new DirectCheckout('SEU TOKEN PUBLICO', false); */
                    var month = document.getElementById("txtDataVencUser").value;
                    var year = document.getElementById("txtDataVencUser").value;

                    var cardData = {
                        cardNumber: document.getElementById("txtNumeroCartaoUser").value,
                        holderName: document.getElementById("txtNomeCartaoUser").value,
                        securityCode: document.getElementById("txtCodSegurancaUser").value,
                        expirationMonth: month.substring(0, 2),
                        expirationYear: "20" + year.substring(3, 5)

                    checkout.getCardHash(cardData, function (cardHash) {
----------------------------> I NEED TO RETRIEVE "cardHash" VALUE IN CODEBEHIND
                    }, function (error) {

I don’t know if this step is correct, but i am using the onClientClick to try to execute the JS before the codebehind:

<asp:Button ID="btnFinalizarCompraJunoUser" runat="server" Text="FINALIZAR COMPRA" OnClientClick="returnHash()" OnClick="btnFinalizarCompraJunoUser_Click" Visible="true" />

I am having trouble figuring out what to do next, can someone help me please?

66 thoughts on “Retrieve value from javascript funcion on client click”

Leave a Comment