javascript - How to get reference to current textbox in a table which contains 50 textboxes? -


basically have table 50 rows , each row has 2 td. 1 input , next 1 has label , dynamic.

refer image enter image description here

dilemma user enters number in textbox(how know 1 if dont want loop through of them?) , on enter key event call javascript function checks if valid , adds corresponding message next tds label. how know reference of input without looping through textboxes call function on each textbox input's enter function?

the following works, based upon (limited available information), though requires handle validation yourself, obviously:

function yourdefinedfunction(){     // need handle validating yourself, somehow.     return false; }  /* binds 'keypress' 'tr' elements, 'listens' see    if take place on/in 'td' element */ $('tbody tr').on('keypress', 'td', function(e){     /* 'this' 'td' element,         'e.target' element within 'td' received event     var cell = this,         target = e.target;      // if key pressed enter key, *and* target input, then:     if (e.which === 13 && target.tagname.tolowercase() == 'input') {          // determine whether entry valid, want:         var validity = yourdefinedfunction() || 'valid';          // , set text of next 'td' element reflect validity:         $(cell).next('td').text(validity);     } }); 

js fiddle demo.

references:


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -