php - How to find selected value of upper row of a table with jquery? -


i have table this. table , rows of table loop php. want option value of upper row when user click option value next row of table. mean is, if click option row number 3, want option value of row number 2. so, try this.

$("select[name='service[]']").change(function(event){         console.log("row"+$("table[name='tbl_list'] tr:last").prev().index()); }); 

but row14 every row clicked. so, how can user selected option value of upper row when click option next row?

use closest parent row , prev previous row

$("select[name='service[]']").change(function(event) {   var val = $(this).closest("tr").prev('tr').find("option:selected").val(); }); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -