Call a href page by passing the input fields of the form

2

I have a page that has several inputs, when I click on the button I open a modal with the result and inside modal I have another button to be clicked but I need to get the form fields and move to the other page. >

My detail button code looks like this:

<div><center><a href="detalhado.html"  class='btn modal-action modal-close red'><strong><i class='mdi-content-add'></i> Detalhado</a></center></strong>

Here I needed to pass the values of the example inputs: href="detailed.html" value = 100000 & months = 24 & rate = 14.15 "

    
asked by anonymous 30.03.2016 / 18:12

1 answer

3

You can use the .serialize () jQuery method to generate the query string valor=100000&meses=24&taxa=14.15 in the button click:

$(function() { // Aguarda o DOM carregar
    $('.btn').on('click', function(e) {
        e.preventDefault(); // Interrompe o browser de seguir para o href do botão

        var href = $(this).attr('href'); // Armazena o valor do atributo href do botão que foi clicado

        // Concatena os valores do form ao href e redireciona para a nova url
        window.location.href = href + '?' + $('form').serialize();
    });
});

link

    
30.03.2016 / 18:40