user1135218
user1135218

Reputation: 403

asp.net apply jquery autocomplete to same boxes with same suffix

I have a jquery autocomplete in my asp.net webform which I would like to use on various textboxes within the page.

I have managed to make it work if I put the full ID of the textbox but, obviously, it only works on that textbox.

All textboxes end on _CUR so I assume there is something missing, but I am not sure how to go about it... Any help is appreciated.

Sys.Application.add_load(function() {                   

        var availableTags = ["EUR","USD",  "ARG","CAD","AUD","TRW","CHI" ];
        $("#_CUR").autocomplete({
        source: availableTags
         });
});

Upvotes: 0

Views: 40

Answers (1)

Tim
Tim

Reputation: 2912

The # selector in jQuery is an exact ID match selector. You are looking for an ends with. There isn't one specifically for ID, but you can use the general attribute ends with selector to achieve the same goal.

Try this:

 var availableTags = ["EUR","USD",  "ARG","CAD","AUD","TRW","CHI" ];
    $("[id$='_CUR']").autocomplete({
    source: availableTags
     });

Documentation available here: http://api.jquery.com/attribute-ends-with-selector/#attributevalue

Upvotes: 1

Related Questions