Java Questions
Java Questions

Reputation: 7963

Javascript method is available but throws exception when calling the method

I have defined the JavaScript method and when I call the method I get the following exception

Uncaught ReferenceError: getProvidersList is not defined.

this is my JavaScript method defined :

function getProvidersList(categoryIndex){
           var index = $('#'+categoryIndex).val();
           console.log("index"+index);
            var url ='${pageContext.request.contextPath}/rechargewallet/rechargeWalletGetSubCategoryRequest.htm';
            $.ajax({
                type: "GET",
                url: url,
                data: "categoryIndex=" + categoryIndex ,
                success: function(response){

                    if('null' != response && (typeof response != 'undefined')){

                        var subCategoriesList = '<select name=subCategoriesList id=subCategoriesList>';
                        for (var i = 0; i < response.length; i++) {
                            var nameOfTheProvider = response[i].nameOfTheProvider;
                            subCategoriesList = subCategoriesList + '<option value="'+nameOfTheProvider'" label="'+nameOfTheProvider'"></option>';
                        }
                        $('#subCategoriesListselectBlock').html(subCategoriesList);
                        $('#subCategoriesList').show(); 

                     }else{
                         $('#categoriesList').show();
                         $('#subCategoriesList').hide();
                     }
                 }
            });
    }

and this is how I call the above method :

<input type="radio" name="categoriesList" id="${categoryName}" value="${category.index}" onclick="getProvidersList(this.id)" />

I also get this exception when the page is loaded :

uncaught SyntaxError: Unexpected token + 

at this line : subCategoriesList = subCategoriesList + '<option value="'+nameOfTheProvider'" label="'+nameOfTheProvider'"></option>';

I am totally confused, normally this kind of exception is thrown when the method is not defined and called but my case, I have defined the method and call the same but then why do I get this kind of undefined exception?

Please advise me how to go about in fixing this..

Thanks.

Upvotes: 0

Views: 76

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388446

You have missing + in the string, since it is a syntax error it is causing the entire script block to not execute thus the getProvidersList function may not get executed

subCategoriesList = subCategoriesList + '<option value="' + nameOfTheProvider + '" label="' + nameOfTheProvider + '"></option>';

Upvotes: 3

Related Questions