Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery each css array
    primarykey
    data
    text
    <p>I have made an each statement which iterates through each class item found. At the same time there is another item with a different class but has the same key. I am needing to get the key from the first each and put it into the 2nd item without having to loop a second time.</p> <pre><code>$('.searchby').each(function(k,v){ // looping through .searchby $(v).live('change',function(){ // when .searchby drop down changed do this selv = $(this).val(); // get value of drop down $.post('file.php',{ 'val' : selv },function(data){ // Below is where I need what I need to happen. // Previously I had .searchby as id but need multiple. // So, what I need it to do is like php. // $('.searchfield[k]).html(data); // &lt;-- like this $('#searchfield').html(data); },'html'); // html, xml, script, json }); }); </code></pre> <p>--EDIT--</p> <p>First, the v in $(v).live should be $(this).live 2nd, I am wanting to convert the single/id pull script to a multi pull script. So, I wrote this which works.</p> <pre><code>$('.searchby').each(function(k,v){ $(this).change(function(){ selv = $(this).val(); $.post('file.php',{ 'val' : selv },function(data){ $('.searchfield').each(function(kk,vv){ if(k == kk) $(vv).html(data); }); //$('#searchfield').html(data); },'html'); // html, xml, script, json }); }); </code></pre> <p>But I would like to be able to take the inner .each out and replace it with:</p> <pre><code>$('.searchfield:eq('+k+')') &lt;-- something like this if I can get it to work </code></pre> <p>So the solution is this:</p> <pre><code>$('.searchby').each(function(k,v){ $(this).change(function(){ selv = $(this).val(); $.post('file.php',{ 'val' : selv },function(data){ $('.searchfield:eq('+k+')').html(data); },'html'); // html, xml, script, json }); }); </code></pre> <p>Thanks everyone</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.
 

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