I've the following code. The return value of the function get_last_catergory_value is always undeifned. I've searched stackoverflow but couldn't debug the issue.
When I show the value being returned just before the return statement it shows the correct value. But when it is returned from function it is undefined. Can you please help me to resolve this?
function fetch_product(brand) {
var brand = brand;
//get last category id
var last_category = 'subcategory10';
var last_category_value = get_last_catergory_value(last_category);
alert(last_category_value); //undefined
}
function get_last_catergory_value(last_category) {
if($('.' + last_category).find(':selected').val() == 'none') {
last_category_number = last_category.substring(11);
last_category_number = parseInt(last_category_number);
last_category_number--;
last_category = last_category.substring(0, 11);
last_category = last_category + last_category_number;
get_last_catergory_value(last_category); //recall the function with values 'subcategory9', 'subcategory8' and so on...
} else {
var value = $('.' + last_category).find(':selected').val();
alert(value); //Gives the correct value here
return value;
}
}
Forgive me if its a trivial issue. Thanks in Advance.
returnon the recursive call.