Schleid Alex

Schleid Alex

  • NA
  • 361
  • 43.9k

Jquery return value undefine

Mar 16 2021 1:50 PM
 Hi everyone,
 
i have this jquery function that add item to a list
 
 $('#ProductCode').on('keypress', function (event) {
        if (event.which == '10' || event.which == '13') {
            event.preventDefault();
            if ($('#ProductCode').val().length != 0) {
                //alert("Please wait, looking for your item", "GPOS")
                var critere = $('#ProductCode').val()
                var SearchResult
                SearchResult = SearchForDuplicate(critere)
                if (SearchResult <0)
                {
                    $.ajax({
                        url: '/Product/ProductInfo',
                        type: 'GET',
                        contentType: 'apllication/html; charset=utf-8',
                        data: { 'Criteria': critere },
                        dataType: 'html',
                        async: false,
                        success: function (result) {
                            $('#dvProductList').html(result)
                            $('#dvProductList').show()
                            $('#dvfooter').show()
                        }
                    });
                    $('#ProductCode').val('')
                }
                else {
                    alert('Product already in the list')
                }
               
            }
        }
    });
 
The uplisting function calls another one to verify for duplicates which return the index value if found and -1 if not found.
 

function SearchForDuplicate(prUPC)
{
    var returnedIndex
    $.ajax({
        url: 'SearchItem',
        dataType: 'html',
        contentType: 'apllication/html; charset=utf-8',
        data: { upc: prUPC },
        type: 'GET',
        async: false,
        success: function (data) {
            returnedIndex = data
            alert('I am here with data = ' + returnedIndex)
            return returnedIndex

        },
        error: function (message) {
            alert('Error ' + message + ' Occured')
        }
    })
}
now the issue is the in the additem function the returned value is always undefined and I cannot spot my error, I am kind of a newbie in this.
 
Your help would be very much appreciated
 
Schleid
 

Answers (4)