Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Save $(this) to a variable and pass it as a parameter (locNode) to your function (during initialization). Also, instead of $(this) you can pass a link to the container element, so each of your initialized autocompletes will know its parent.</p> <p><strong>Update:</strong> The following may not be 100% correct in terms of autocomplete initialization, but its a solid illustration how to create <strong>2 unique instances of locPrep</strong> in <code>&lt;div id="myDiv1"&gt;</code> and <code>&lt;div id="myDiv2"&gt;</code></p> <pre><code>myContainer1 = $('#myDiv1'); myContainer2 = $('#myDiv2'); myAutocompleteInstance1 = new locPrep(myContainer1); myAutocompleteInstance2 = new locPrep(myContainer2); </code></pre> <p><strong>Update2</strong>: how to pass <strong>this</strong></p> <pre><code>function locPrep(locNode, currentThis) { /// use currentThis instead of $(this) inside locPrep function $locNode.autocomplete({ source: function (request, response) { $locDiv = currentThis.closest("div.locWrapper"); $stateNode = $locDiv.find("input.state"); $countryNode = $locDiv.find("input.country"); $.post("/FormHost/AutocompleteLocList", {state:$stateNode.val(), country:$countryNode.val(), term:request.term }, function (data) { response(data); } ); } }); } </code></pre> <p><strong>init:</strong></p> <pre><code>myAutocompleteInstance1 = new locPrep(myContainer1, $(this)); </code></pre> <p><strong>new</strong> will make sure that value of currentThis is unique in each instance of locPrep</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload