0

what I'm trying to achieve is that request.term changes depending on which input field I'm using

   $("#field1", "#field2").autocomplete({
            source: function (request, response) {
             $.ajax({
                 url: 'autocomplete.php',
                 data: {field1 : request.term },
                 dataType: "json",
                 success: response,
                 error: function () {
                     response([]);
                 }
             });
            },
            autoFocus: true
        });
    });

Code currently uses 'field1', I tried using $(this).attr('id') but I may have done it in the wrong way, so I'd need a little help, thank you!

1 Answer 1

0

have you try in this way

jQuery(document).on('keydown','#field1,#field2',function(){
 $(this).autocomplete({
        source: function (request, response) {
         $.ajax({
             url: 'autocomplete.php',
             data: {field1 : request.term },
             dataType: "json",
             success: response,
             error: function () {
                 response([]);
             }
         });
        },
        autoFocus: true
    });
})
});

Your Answer

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