I have search a lot but google just return me how to get the selected value of a select element
$('#some_id').select(function() {
// how can i store the selected value in a variable.?
alert('the selected value');
});
I have search a lot but google just return me how to get the selected value of a select element
$('#some_id').select(function() {
// how can i store the selected value in a variable.?
alert('the selected value');
});
You can use change event to get selected value. In the event handler you can use $(this).val()
of this.value
to get the selected value.
$('#some_id').change(function(){
// how can i store the selected value in a variable.?
v = this.value;
alert('the selected value' + this.value);
});
Use .change() event. Something like this:
var current_value = 1;//can define any value null also
$('#some_id').change(function(){
current_value = $(this).val();//storing
alert(current_value);
});
Note: if you want to store value in variable and use it anywhere else then you must define it globally like i did.
you can try like this:
$('#select_id').change(function(){
var sval = $('#select_id').val();
alert('the selected value' + sval);
});