Jquery selectpicker default selected value from selectbox

4.2k views Asked by At

My main problem was I was trying to get values from my form and selectboxes are using selectpicker jquery plugin, they look really cool now! But in other I found a bug, when I put default selected by html tag "selected" it always gives selected value.

https://github.com/silviomoreto/bootstrap-select

I'm trying to get value by this code but it always return same value.

var pets_name = $('#pets_name').val(); 
1

There are 1 answers

0
Mehmet Uyarovic On BEST ANSWER

I tried to search setting default value option but I couldn't find anything about it on seletpickers github.

I solved my problem by this code. :selected gives us this value. I hope it will help someone,sometimes we need small fixes not big ones.

var pets_name = $('#pets_name:selected').val();