javascript - Get a dropbox and textbox values inside table using jQuery -


i'm trying easy thing. values 1 table row onfocus event. have bad practice assignment, insert database without button click i've decided use onfocus event last cell in row.

the problem i'm new jquery , javascript i'm having troubles getting dropbox , textbox selected , input values variables pass later code-behind using ajax.

can me problem?

to keep simple html 1 of rows, others same , table static:

<table class="default-table" id="tbltest">     <tr>         <td>             <select name="client" class='client'>                 <option>choose client</option>                 <option>client 1</option>                 <option>client 2</option>             </select>         </td>         <td>             <select name="project" class='project'>                 <option>choose project</option>                 <option>project 1</option>                 <option>project 2</option>             </select>         </td>         <td>             <select>                 <option>choose category</option>                 <option>front-end development</option>                 <option>design</option>             </select>         </td>         <td>             <input type="text" class="in-text medium" name="description" />         </td>         <td class="small">             <input type="text" class="in-text xsmall" name="time" />         </td>         <td class="small">             <input type="text" class="in-text xsmall" name="time" />         </td>     </tr>     <tr>         <td>             <select>                 <option>choose client</option>                 <option>client 1</option>                 <option>client 2</option>             </select>         </td>         <td>             <select>                 <option>choose project</option>                 <option>project 1</option>                 <option>project 2</option>             </select>         </td>         <td>             <select>                 <option>choose category</option>                 <option>front-end development</option>                 <option>design</option>             </select>         </td>         <td>             <input type="text" class="in-text medium" />         </td>         <td class="small">             <input type="text" class="in-text xsmall" />         </td>         <td class="small">             <input type="text" class="in-text xsmall" />         </td>     </tr> </table> 

and these ways i've been trying of values using jquery, non of them working properly:

<script type="text/javascript">          $("#tbltest td:nth-child(6)").focusout(function (event) {              var $td = $(this).closest('tr').children('td');             // tr2 use value of id attribute <tr>, deleted because want              // use same script each row              //var time = $('#tr2 td.eq(5) input').text();             //var client = $('#tr2 td.eq(1)').text();             var project = ('$td.eq(2) select option:selected').text();             var overtime = $td.eq(6).text();         }); </script> 

how can values? lot!

you can this:-

$("#tbltest td:nth-child(6)").focusout(function () {     var parentrow = $(this).parents('tr')[0];     var time = $('input[name="time"]', parentrow).val();     var client = $('.client option:selected', parentrow).text();     var project = $('.project option:selected',parentrow).text();     var overtime = $('input[name="overtime"]', parentrow).val();     //similarly can find other values }); 

note: think last have typed time textbox twice have considered overtime.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -