Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I am having a requirement, where i need to select the span's value(inner Text)depending on the corresponding checkbox checked.
I am able to get the value of the checked checkbox by performing the each function--

JavaScript
var fIds = [];
       $("#tblSearchResult input:checkbox[name=assignChkBx]:checked").each(function () {
           var id = $(this).attr("value");
           fIds.push("" + id + "");
       });


how can i get the value of the corresponding span as well here so that along with the checkbox value, i can append span's text also to the fIds?

Please provide inputs!!!

Thanks
Posted
Comments
Tejas Vaishnav 19-Mar-14 8:46am    
can you share your html code also, so it will be very helpful to get your solution...
adityasahver 19-Mar-14 9:36am    
so here is the table structure
<pre lang="HTML">
<table id="tblSearchResult">
<tr class="odd"><td class=" sorting_1"><input type="checkbox" value="372" name="assignChkBx" id="assignChkBx" class="check-box"></td><td class=""><span value="Rental Netwrok 1" name="testing123">test-45_02082014020925</span></td></tr>
<tr class="even"><td class=" sorting_1"><input type="checkbox" value="363" name="assignChkBx" id="assignChkBx" class="check-box"></td><td class=""><span value="234" name="testing123">test-587_02072014220755</span></td></tr>
<tr class="even"><td class=" sorting_1"><input type="checkbox" value="364" name="assignChkBx" id="assignChkBx" class="check-box"></td><td class=""><span value="237" name="testing123">test-561_02072014220755</span></td></tr>
<tr class="even"><td class=" sorting_1"><input type="checkbox" value="365" name="assignChkBx" id="assignChkBx" class="check-box"></td><td class=""><span value="Rental 2" name="testing123">test-560_02072</span></td></tr></table></pre>

Now if i am selecting the first checkbox, i want to get the value of the corresponding span as well.
Thanks

1 solution

here is your solution...

JavaScript
$('#tblSearchResult tr').each(
               function () {
                   var row = $(this);
                   if (row.find('input[type="checkbox"]').is(':checked')) {
                       var id = row.find('[name="assignChkBx"]').attr("value");
                       var spantext = row.find('[name="testing123"]').html();
                   }
               });
 
Share this answer
 
Comments
Tejas Vaishnav 19-Mar-14 10:50am    
if it will help you, don't forget to accept it as your solutions and also vote my answer.
adityasahver 20-Mar-14 4:22am    
awesome thanks..!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900