Click here to Skip to main content
15,892,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have iterated through table and able to get td elements and assigned to a variable 'col'

But how do i traverse inside to get the value of input element inside my td 

 <td class='dropdown generic-td'>
    <input data-qid='327'  value="" class='myclass'  type=text readonly />
 </td>


my code:
var table = document.getElementById("pdfCarryOver");

   var k = 40;

   for (var i = 0, row; row = table.rows[i]; i++) {
       console.log(row);
       for (var j = 0, col; col = row.cells[j]; j++) {
           // console.log(col);
           if (j == 0) {
               var value = $(col).text();
               console.log("Inner Text only: " + value);

               if (value.length > 0) {
                   pdf.text(40, k, value);
               }
           }
           if (j === 1) {

               console.log(col);
               var value = $(col + " input").value();

               console.log("Inner Value only: " + value);

               if (value.length > 0) {
                   pdf.text(40, k, value);
               }

               break;
           }
       }

       k += 20;
       console.log("---------------------");


What I have tried:

var value = $(col + " input").value();
Posted
Updated 27-Feb-18 7:39am
Comments
Richard Deeming 27-Feb-18 12:16pm    
Try:
var value = $(col).find("input").val();
istudent 27-Feb-18 12:19pm    
thank you sir

1 solution

As mentioned in the comments, the solution is:
JavaScript
var value = $(col).find("input").val();

.find() | jQuery API Documentation[^]
.val() | jQuery API Documentation[^]
 
Share this answer
 

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