Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery autocomplete for multiple fields using id, but not using class; using serialize if possible
    text
    copied!<p>HTML input fields</p> <pre><code>&lt;input type="text" name="partner_name_or_description[]" id="partner_name_or_description1" class="row_changed1"/&gt; &lt;input type="text" name="partner_name_or_description[]" id="partner_name_or_description2" class="row_changed2"/&gt; &lt;input type="text" name="partner_name_or_description[]" id="partner_name_or_description3" class="row_changed3"/&gt; </code></pre> <p>Part of jquery autocomplete code (that works)</p> <pre><code>$("#partner_name_or_description1:input, #partner_name_or_description2:input, #partner_name_or_description3:input").autocomplete( "__autocomplete_source.php", </code></pre> <p>In jquery there are: partner_name_or_description1, 2, 3 etc.... Instead of this long list of 1, 2, 3 etc. want to use something short with serialize (or in other possible way).</p> <p>At first get these 1,2,3... with this code</p> <pre><code>$('[id^="partner_name_or_description"]').each(function (index, partner_name_or_description) { var s_id = partner_name_or_description.id.substring(27); }); </code></pre> <p>Then instead of that long list trying to make something like this</p> <pre><code>$("#partner_name_or_description" + s_id + " :input").serialize().autocomplete( </code></pre> <p>It does not work. If View source, see </p> <pre><code> $("#partner_name_or_description" + s_id + " :input").serialize().autocomplete( </code></pre> <p>Do not understand reason... May be incorrectly use <code>serialize().autocomplete</code></p> <p>Or may be must not use <code>serialize()</code> and must use something else.</p> <p>I can not use <code>class="row_changedX"</code> because it is necessary for other purposes (class must be like row_changed1, 2, 3; for each row class name must be different).</p> <p><strong>Working code</strong></p> <pre><code>/*Actually do not understand why this is necessary, but if I delete all uncommented, then code does not work*/ function findValue(li) { /*if( li == null ) return alert("No match!"); // if coming from an AJAX call, let's use the CityId as the value if( !!li.extra ) var sValue = li.extra[0]; // otherwise, let's just display the value in the text box else var sValue = li.selectValue; alert("The value you selected was: " + sValue);*/ } function selectItem(li) { findValue(li); } function formatItem(row) { return row[0] + " (id: " + row[1] + ")"; } $('[id^="partner_name_or_description"]').autocomplete("__autocomplete_source.php", { delay:10, minChars:2, matchSubset:1, matchContains:1, cacheLength:10, onItemSelect:selectItem, onFindValue:findValue, formatItem:formatItem, autoFill:true }//{ delay:10, )//.autocomplete(; </code></pre>
 

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