Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery.inArray keeps returning -1
    text
    copied!<p><strong>EDIT</strong> jQuery.inArray kept failing to do string != int comparisons, and this was resolved with the help of ShankarSongoli. Originally it was thought to be a variable scope issue, so please remember to look at all aspects and not just one in any given problem.</p> <pre><code> omit_all_user_contacts = new Array(); add_contacts = new Array(); function is_added_contact(id) { if ( jQuery.inArray(id, add_contacts) == -1 ) return false; return true; } function selectcontacts(userid){ document.getElementById("ic"+userid).checked = true; omit_all_user_contacts.push(userid); var buf = '&lt;table class="contactlist" width="100%"&gt;'; buf = buf + "&lt;tr class='contactlistheader'&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Contact Name&lt;/td&gt;&lt;td&gt;Company&lt;/td&gt;&lt;td&gt;Email&lt;/td&gt;&lt;td&gt;Profession&lt;/td&gt;&lt;/tr&gt;"; var tmp; jQuery.getJSON('/user/get_user_contacts/'+userid, function(data) { jQuery.each(data.contacts, function(key, value) { buf = buf + "&lt;tr&gt;&lt;td&gt;&lt;input type='checkbox' name='manualcontact[]' onclick='manualcontact(" + value.id + ",this.checked)' "; alert(is_added_contact(value.id)); if ( jQuery.inArray(value.id, add_contacts) &gt; -1 ) { buf = buf + " checked "; } buf = buf + "/&gt;&lt;/td&gt;"; buf = buf + "&lt;td&gt;" + value.firstname + " " + value.lastname + "&lt;/td&gt;"; buf = buf + "&lt;td&gt;" + value.company + "&lt;/td&gt;"; buf = buf + "&lt;td&gt;" + value.email + "&lt;/td&gt;"; buf = buf + "&lt;td&gt;" + value.profession + "&lt;/td&gt;&lt;/tr&gt;"; }); buf = buf + '&lt;/table&gt;'; iBox.show(buf); }); } function manualcontact(id,val) { if ( val == true ) { add_contacts.push(id); } else { add_contacts.splice( jQuery.inArray(val, add_contacts), 1 ); } } </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