Reputation: 617
function getSelectData(id) {
var value='';
// set value to be the current selected value
value = jQuery(id+" option:selected").val();
// change value whenever the box changes
jQuery(id).change(function () {
value = jQuery(id+" option:selected").val();
});
console.log(value);
return value;
}
Thanks to @Hogan , he help me but still i can not get wanted result , how i can get variable value
, outside function change
, here is this example http://jsfiddle.net/ZvuMh/ , and every time when i'm changing select box , value is a
. Thank You for your spending time
Upvotes: 0
Views: 810
Reputation: 10119
You can't unless you move it to be a global variable. As it is, the line "console.log(value)" will only print the value before the function change() is called. (change() gets called when something changes....but that is long after getSelectData() has returned).
Upvotes: 1