I'm having trouble fetching the index of another field from jquery .each() function. I want to fetch the value of the input with the name line_id[] :
$('input[name=bl_caps[]]').each(function(index){
var line_id = $('input[name=line_id[]]').val();
var caps = $(this).val();
alert('line id: ' + line_id + '<br/>' + 'caps: ' + caps);
});
HTML:
<?php foreach(){ ?>
<input type="hidden" name="line_id[]" id="line_id" value="<?php echo $sbl->BusLineID; ?>"/>
<td><input type="text" name="bl_caps[]" id="bl_caps"/></td>
<?php } ?>
I'm planning to do it like this:
var line_id = new Array();
$('input[name=line_id[]]').each(function(index){
line_id[index] = $(this).val();
});
$('input[name=bl_caps[]]').each(function(index){
var line_ids = line_id[index];
var caps = $(this).val();
alert('line id: ' + line_ids + '<br/>' + 'caps: ' + caps);
});
But I'm hoping that I could find a better answer here:)