How to load reload page when selecting dropdownlist item from jquery list passing parameters?

0

I have a select

<select id="selecao" name="tipoLocal">
  
  <option value="casa">Casa</option>
  
  <option value="predio">Predio</option>
  
  <option value="predio">Terreno</option>
  
</select>

It is possible in jquery to reload page passing as parameter as soon as you select a select item, without clicking any button, only when selecting an option already loads the url "www.example.com/{parametro}", where this url pass to a controller in java? How to do?

    
asked by anonymous 18.02.2016 / 14:28

2 answers

1

To do this you can use jQuery's .change () event and pass the value of the selected item to a% with%. It would look like this:

$('#selecao').change(function(){
var parametro = $(this).find(':selected').val()

 location.href = 'www.exemplo.com/' + parametro;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><selectid="selecao" name="tipoLocal">
  
  <option value="casa">Casa</option>
  
  <option value="predio">Predio</option>
  
  <option value="terreno">Terreno</option>
  
</select>
    
18.02.2016 / 14:50
1

You can do with ajax too.

 $("#combo").change(function(){

        var value = $('#combo :selected').text();

         $.ajax({
                  type: "POST",
                   url: 'controller/metodo',
                   cache: false,
                   data: value,
                   dataType: '',
                   contentType: '',
                   success: function () {

                   }
         });
    })
    
18.02.2016 / 14:59