javascript - Get Autcomplete value inside table -


how can value of autocompletes inside table>tbody>tr>td...??

element.children[0].firstelementchild.value 

the above statement returning null

element.children[1].firstelementchild.value 

the above statement returning value of dropdown inside 2nd cell of tr.

element.children[2].firstelementchild.value  <script> function summarisetable(tableid) {     var tbody = document.getelementbyid(tableid).lastelementchild,         reduced = array.prototype.map.call(tbody.getelementsbytagname('tr'), function (element) {              return {                 code: element.children[1].firstelementchild.value,                 sqin: +(element.children[6].firstelementchild.value)             };         }).reduce(function (acc, rowdata) {             if (!acc.hasownproperty(rowdata.code)) {                 acc[rowdata.code] = rowdata.sqin;             //  console.log(code);             } else {                 acc[rowdata.code] += rowdata.sqin;             //  console.log(rowdata.sqin);             }              return acc;         }, {});      //emptynode(tbody);     //console.log(reduced);     var tbody = document.getelementbyid('summary')     object.keys(reduced).foreach(function (code) {         var row = document.createelement('tr'),             tdcode = document.createelement('td'),             //tdrtfm = document.createelement('td'),             tdsqin = document.createelement('td');          tdcode.appendchild(document.createtextnode(code));         tdsqin.appendchild(document.createtextnode(reduced[code]));         row.appendchild(tdcode);         //row.appendchild(tdrtfm);         row.appendchild(tdsqin);         tbody.appendchild(row);     }); }  document.getelementbyid('summarise').addeventlistener('click', function () {     summarisetable('tblone'); }, false); </script> 

html: rough structure ..

<table id="tblone">     <thead>         <tr>             <th>codes</th>             <th>sqin</th>         </tr>     </thead>     <tbody>         <tr>             <td><input style="width:90px" class="coderule" id="code_0' + id + '" name="code_0' + id + '"/></td>                 <td><input type="text" id="sqin_0" name="sqin_0" value="25"/></td>         </tr>         <tr>                     <td><input style="width:90px" class="coderule" id="code_1' + id + '" name="code_1' + id + '"/></td>                 <td><input type="text" id="sqin_1" name="sqin_1" value="25"/></td>          </tr>         <tr>             <td><input style="width:90px" class="coderule" id="code_2' + id + '" name="code_2' + id + '"/></td>                 <td><input type="text" id="sqin_2" name="sqin_2" value="25"/></td>           </tr>         <tr>             <td><input style="width:90px" class="coderule" id="code_3' + id + '" name="code_3' + id + '"/></td>                 <td><input type="text" id="sqin_3" name="sqin_3" value="25"/></td>         </tr>         <tr>             <td><input style="width:90px" class="coderule" id="code_4' + id + '" name="code_4' + id + '"/></td>                 <td><input type="text" id="sqin_4" name="sqin_4" value="25"/></td>         </tr>         <tr>               <td><input style="width:90px" class="coderule" id="code_5' + id + '" name="code_5' + id + '"/></td>                 <td><input type="text" id="sqin_5" name="sqin_5" value="25"/></td>         </tr> </tbody> </table> <button id="summarise">summarise</button> 

here output come:

 <table class="table grey-table" id="summary">   <thead>         <tr>             <th>code</th>             <th>slab sq in</th>             <th>project sq in</th>             <th>no. slabs</th>             <th>unit price</th>             <th>total price</th>         </tr>     </thead>     <tbody>      </tbody>   </table> 


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -