jQuery select by two name roots and perform one of two function depending on which root was selected

Posted by RetroCoder on Stack Overflow See other posts from Stack Overflow or by RetroCoder
Published on 2012-09-27T15:19:48Z Indexed on 2012/09/27 15:37 UTC
Read the original article Hit count: 180

Filed under:

I'm trying to get this code to work in jQuery and I'm trying to make sure that for each iteration of each root element, its alternate root element for that same iteration doesn't contain anything. Otherwise it sets the .val("") property to an empty string. Looking for a simple solution if possible using search, find, or swap.

Each matching number is on the same row level and the same iteration count.

I have two input types of input text elements with two different root names like so:

1st Root is "rootA"

 
    <input type="text" name="rootA1" />
    <input type="text" name="rootA2 />
    <input type="text" name="rootA3" />
   
2nd Root is "rootB"
 
    <input type="text" name="rootB1" />
    <input type="text" name="rootB2 />
    <input type="text" name="rootB3" />
   

On blur if any of rootA is called call function fnRootA();. On blur if any of rootB is called call function fnRootB();.

Again, I'm trying to make sure that for each iteration like 1 that the alternate root doesn't contain anything, else it sets the .val("") property to an empty string of the root being blurred.

My current code works for a single element but wanted to use find or search but not sure how to construct it..

$("input[name='rootA1']").blur(function(e) {
   fnRootA(1); // this code just removes rootA1's value val("") 
              //if rootB1 has something in it value property
             // the (1) in parenthesis is the iteration number
});

© Stack Overflow or respective owner

Related posts about jQuery