mysql - Finding the row for a cell in jquery -


i newbie in programming , learning jquery. have question if have button in column attribute , when click button in cell attribute want find value of unique id cell i.e, if if attribute name approved value toggle between yes , no via button click, want fetch value of unique id name attibute in jquery, can update value approved using ajax call.

<table> <th>s.no</th> <th>name</th> <th>submitted by</th> <th>approved</th> <tr> <td>1.</td> <td>xyz</td> <td>21-3-04</td> <td>no <input type = "button" onclick = "toggle()" value = "click"/></td></tr> . . . </table>  <script> function toggle(){ //i want fetch value of name attribute row in button clicked. , later want call ajax call url consist of update query. } </script> 

first calling "attribute" "element".

secondly rid of inline onclick= attribute.

then, using appropriate jquery methods:

$(document).ready(function () {     $("table td input[type='button']").click(function () {         var name = $(this).closest('tr').children().eq(1).text();         // name         alert(name);     }); }); 

demo: http://jsfiddle.net/evugv/1

that is, bind click handler of input button elements in table (ideally you'd give table id attribute , use that, e.g., $("#idoftable td")). within function, this set particular button clicked, there can use jquery's dom navigation methods go containing tr element , within tr's children select second , text.


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 -