Jquery Loop For Script
I'd like to run script for each field which id begins with 'imie' and ends with numbers 1 to 10. Each field 'imie' depends on field 'nazwisko' with the same number at the end eg. '
Solution 1:
If you colud give class name to imie
element which is same as the id of nazwisko
element, it would be easy. Then the code will be
$("[id^=imie]").change(function () {
alert($("." + this.id).val());
});
HTML
<td><input type='text' name='nazwisko1' id='nazwisko1'></td>
<td><input type='text' class="nazwisko1" name='imie1' id='imie1'></td>
Solution 2:
You'd be better off putting a validation function on the blur event of those fields. For example
$('#thatTable').on('blur', 'input.imie', function(evt) {
var nazwisko = $(this).parent(td).prev('td').find('input.nazwisko');
//now do so something with nazwisko's data
});
This assumes you add a CSS class to each field to help the jQuery selector.
Post a Comment for "Jquery Loop For Script"