i need to get selected option value in JqueryUI SelectMenu out of change event, But i can't get value out of Change function or selectmenu function, how to do it/
var iSelectedValue;
var map="";
$("#drpRegionName").selectmenu({
change: function (event, ui) {
iSelectedValue = ui.item.value;
console.log(iSelectedValue); //Working
},
select: function (event, ui) {
map = $(this).val();
console.log(map); //working
}
});
console.log(map); // not working
console.log($(iSelectedValue); // not working
out of the function its undefined.
map
andiSelectedValue
variable gets assigned a value afterchange
/select
event. So your outside console return asundefined
. - randomiSelectedValue
is declared withvar' in
change` function scope. So this variable is not visible outside of this scope. And as mentioned above by @randomSoulmap
variable is declared outside ofchange
function. - dganencochange
event callback function. - 04FS