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

Asked

Viewed 908 times

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 a page by passing as parameter as soon as you select an item from select, without having to click any button, only when selecting an option you already load the url "www.exemplo.com/{parameter}", where this url passes to a controller in java? How to do?

  • Well I don’t know if I got it right, you want to call a controller when selecting some combo item?

2 answers

1


To do this you can use the event .change() jQuery and pass the value of the selected item to a location.href. That would be your example:

$('#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>
<select id="selecao" name="tipoLocal">
  
  <option value="casa">Casa</option>
  
  <option value="predio">Predio</option>
  
  <option value="terreno">Terreno</option>
  
</select>

  • Thank you solved the problem.

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 () {

                   }
         });
    })

Browser other questions tagged

You are not signed in. Login or sign up in order to post.