Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Why this function doesn’t work in ‘for loop’ ? [jquery] Re: Why this function doesn’t work in ‘for loop’ ? [jquery]

#127653
pixelgrid
Participant

if you watch your code after focusing on the first input the field that appears is the fifth one.thats because of the k var at the time of the code being executed.

i came up with this which works

for(var i=2; i<=5; i++ ){
$(‘#row’+i).hide();
}

$(‘input’).focus(function(){
var num = $(this).attr(‘id’).match(/d+$/)[0];
$(‘#row’+(+num+1)).show();
});