How to do a search with .serialize ()

2

I have this Search / Serialize JSFiddle , but I did not want it get the name of select , only value of option and do search.

Can you ignore name and only use value ?

Here is the code:

    var host = "http://www.rs1.com.br/";
    $(document).ready(function(){
        $('#send').click(function(){
            var variables = $('#form').find('campo').serialize();
            var destination = host + variables.replace('=','/');
            $('#link').html(destination)
            window.open(destination);      
        });
    });

<form id="form">
    <select>
        <option value="tutto-moto" class="campo">Tutto</option>
    </select>
    <select>
        <option value="Acessorio" class="campo">Tutto</option>
    </select>    
    <select>
        <option value="produto" class="campo">Iphone+4s</option>
    </select>   
</form>
<button type="button" id="send" class="btn">Buscar</button>
    
asked by anonymous 06.10.2014 / 16:24

1 answer

3

My knowledge of JS / jQuery is not so broad, but you can do it as well JSFiddle .

Basically just scroll through the elements instead of using serialize , and treat the string. Now you can do with serialize I do not know.

$('#send').click(function(){
    var variables = '';
    // Percorre todos os campos campos dentro da tag select com a classe campo
    $('#form select').find('.campo').each(function(){
       variables += $(this).attr('value')+'/'; // Concatena o valor do option
    });
    var destination = host + variables;
    $('#link').html(destination)
    window.open(destination);
});
    
06.10.2014 / 16:45