I have array of two textboxes in a table, on blur of one text box in a row I have to copy part of the text from one to other, similarly based on text typed in first text box I need to fill the second on blur. How do I do this in jQuery. I tried to use .each but does not seems to be working. Hope I am clear in my question, please help me resolving this.
I have the one name for each text box, mean finally I will get two arrays 开发者_开发百科if I get them in java class.
Thanks in advance
<input type="text" id="txt1" />
<input type="text" id="txt2" />
$('#txt1').blur(function (){
$('#txt2').val($(this).val());
});
if u need for more than one and if i understand u properly
<input type="text" class="txt1" />
<input type="text" class="txt2" />
$('.txt1').each(function (i,n){
$(n).blur(function (){
$('.txt2').eq(i).val($(n).val());
});
});
Try something like this
$( '.yourTable input[name=textboxname]' ).blur( function() {
var text = $( this ).val();
//Crop/change the text here, whatever you want to do
$( this ).parent().next( 'td' ).children( 'input[name=othertextboxname]' ).val( text );
} );
Since your textboxes got names, you can use them in your jQuery selector. The rest is changing that text and traversing to the next textbox in the same row.
精彩评论