Question

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(); 
Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top