0

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.

1 Answer 1

3

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>';
Sign up to request clarification or add additional context in comments.

2 Comments

:) Thanks a lot, your eyes rock ... :)
@Anto if you use a proper IDE this kind of bugs will never come

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.