Tuesday 15 March 2011

ajax - How to get value of row if checkbox in that row is clicked in jquery -



ajax - How to get value of row if checkbox in that row is clicked in jquery -

i value of whole row if same row check box checked. example

<table id="tbl" border="1"> <tr><input type="checkbox" id="selectall"/> <td> <input type="checkbox"/></td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr><td><input type="checkbox"/></td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr><td><input type="checkbox"/></td> <td>2</td> <td>3</td> <td>5</td> </tr> </table> <input type="button" value="save"/> $('#selectall').click(function(event) { if(this.checked) { // iterate each checkbox $(':checkbox').each(function() { this.checked = true; }); } else { $(':checkbox').each(function() { this.checked = false; }); } }); $("#save").click(function(){ /if selected value has pass through ajax 1 1 row/ });

if press save button have select row values ever checked. please refer fiddle. please help me . in advance

try

class="snippet-code-js lang-js prettyprint-override">$('#selectall').click(function(event) { $(':checkbox').prop('checked', this.checked); }); $("#save").click(function() { //reset logger $('#log').empty(); //get checked checboxex $('#tbl input:checkbox:checked').each(function() { //for each checked checkbox, iterate through parent's siblings var array = $(this).parent().siblings().map(function() { homecoming $(this).text().trim(); }).get(); //to print value of array $('#log').append(json.stringify(array)) }) }); class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <input type="checkbox" id="selectall" /> <table id="tbl" border="1"> <tr> <td> <input type="checkbox" /> </td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td> <input type="checkbox" /> </td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td> <input type="checkbox" /> </td> <td>2</td> <td>3</td> <td>5</td> </tr> </table> <input type="button" id="save" value="save" /> <div id="log"></div>

jquery ajax checkbox

No comments:

Post a Comment