javascript - Get current object with the on() method -


how can update specific input of current line event "change" called?

here script:

$('#absence-table').on('change', '.from input, .to input',function() {     var   = $('.from input').val();     var     = $('.to input').val();      if (from != "" && != "")     {         d1 = gettimestamp(from);         d2 = gettimestamp(to);          if(d1 <= d2)         {             $('.result input').val(new number(math.round(d2 - d1)+1));         }          else         {             $('.result input').val(0);         }     } }); 

html:

<table class="table table-bordered" id="absence-table"> <tr>     <th>absence type</th>     <th>from</th>     <th>to</th>     <th>days requested</th>     <th>morning</th>     <th>afternoon</th>     <th colspan="2">comment</th> </tr> <tr class="main-abs-line">     <td>         <select name="absence-type" class="input-small">             <option value="t1">type1</option>             <option value="t2">type2</option>         </select>     </td>     <td class="from"><input type="text" class="input-small" /></td>     <td class="to"><input type="text" class="input-small" /></td>     <td class="result"><div class="text-center"><input type="text" class="input-xsmall" /></div></td>     <td class="morning"><div class="text-center"><input type="checkbox"></div></td>     <td class="afternoon"><div class="text-center"><input type="checkbox"></div></td>     <td colspan="2"><input type="text" /></td> </tr> // tr added append() method 

currently, result input of first line updated, current result input copied first. that's strange because values '.from input' , '.to input' correct (values of current line).

normally use $(this) current object, on() method don't know way it.

i believe looking for:

$('#absence-table').on('change', '.from input, .to input',function() {     $tr = $(this).closest("tr");     var   = $tr.find('.from input').val();     var     = $tr.find('.to input').val();      if (from != "" && != "")     {         d1 = gettimestamp(from);         d2 = gettimestamp(to);          if(d1 <= d2)         {             $tr.find('.result input').val(new number(math.round(d2 - d1)+1));         }          else         {             $tr.find('.result input').val(0);         }     } }); 

this assumes have several tr's containing .to, .from, , .result , when .to or .from gets updated, want .result in same tr updated.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -