Question

I have a generic function that populates a 2nd field from a first. In cases where there is a label, it creates a problem, as the label is the

next() 

element.

So, i end up with:

function buildoptions(el){
  var element = el.id;
  var $flda = $('#'+element);   
  var $fldb = $flda.next().next();  //double here to skip the label
      .....
}

but of course, i have a few fields that don't have labels so this breaks...

I was thinking

var $fldb = $flda.next().not(label);

would work, but it does not. It actually throws an error

Error: 'label' is undefined

ideas?

HTML looks like:

<label for="inp_29">Select drives next</label>
<select id="inp_29" name="driver1" onchange="buildoptions(this);">
  <option value="" selected="selected">Select</option>
  <option value="option1">option1</option>
  <option value="option2">option2</option>
</select>

<!--* SOMETIMES OPTIONAL LABEL*-->
 <label for="inp_30">No default options</label>
<!--* END SOMETIMES OPTIONAL LABEL*-->
<select id="inp_30" name="filler1">
  <option value="Select Driver First">Select Driver First</option>
</select>

I also have a tabular case:

<TR id="dynrow_table35_1" class="">
<TD class="odd">  
<LABEL for="inp_331">absel</LABEL>
<SELECT id="inp_331" onchange="buildoptions(this);" name="absel_1"> 
<OPTION value="">Select</OPTION>
<OPTION value="option1">option1</OPTION>
<OPTION value="option2">option2</OPTION>
</SELECT></TD>
<TD class="odd"><LABEL for="inp_341">No default options</LABEL>
<SELECT id="inp_341" name="abfil1">
<OPTION value="Select Driver First">Select Driver First</OPTION>
</SELECT> </TD>
</TR>

id's are dynamicly built and i will never know their actual ID.

Was it helpful?

Solution

What about this ..

var $fldb = $flda.nextAll('input').eq(0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top