0

function readingTable(){
const res=[...document.querySelectorAll("#stockinboundedittable tr")].slice(1).map(tr=>
  Object.fromEntries(
[...tr.querySelectorAll("input")].slice(1).map(inp=>[inp.id.replace(/.*stockinbound/,"").replace(/\d+$/,""),inp.value])));
document.getElementById("demoSpan").innerHTML=JSON.stringify(res);
}
<table style="width:100%;   border-collapse: collapse;  text-align: center;" id="stockinboundedittable">
      
        <tr>
          <th style="display:none;">subcategory</th>
          <th>Sl.No</th>
          <!--<th>I.U.Code</th>-->
          <th>Item Name</th>
          <th> old stock</th>
          <th> new stock</th>
          <th> Total Stock</th>
          <th> qty</th>
          <th>Edit</th>
        </tr>
     
      <tr>
        <td style="display:none;">tmcsubctgy_2</td>
        <td>
          <input style="    width: 100%;" id="slno1editinbound1" value="1" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundedititemname1" value="Fresh Goat Meat - Curry Cut" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditoldstock1" value="20" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditnewstock1" value="10" readonly="">
        </td>
        <td>
        <input style="    width: 100%;" id="stockinboundedittotalstock1" value="30" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="inboundeditqty1">
        </td>
        <td>
          <button style="background: #fdd110; width: 100%;" id="stockinboundeditditbut1">EDIT</button>
        </td>
      </tr>
      <tr>
        <td style="display:none;">tmcsubctgy_5</td>
        <td>
          <input style="    width: 100%;" id="slno1editinbound2" value="2" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundedititemname2" value="Everest - Kasur Methi" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditoldstock2" value="0" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditnewstock2" value="10" readonly="">
        </td>
        <td>
        <input style="    width: 100%;" id="stockinboundedittotalstock2" value="10" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="inboundeditqty2">
        </td>
        <td>
          <button style="background: #fdd110; width: 100%;" id="stockinboundeditditbut2">EDIT</button>
        </td>
      </tr>
      <tr>
        <td style="display:none;">tmcsubctgy_13</td>
        <td>
          <input style="    width: 100%;" id="slno1editinbound3" value="3" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundedititemname3" value="Fresh Coconut Milk 150 ml" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditoldstock3" value="10" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditnewstock3" value="10" readonly="">
        </td>
        <td>
        <input style="    width: 100%;" id="stockinboundedittotalstock3" value="20" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="inboundeditqty3">
        </td>
        <td>
          <button style="background: #fdd110; width: 100%;" id="stockinboundeditditbut3">EDIT</button>
        </td>
      </tr>
      <tr>
        <td style="display:none;">tmcsubctgy_5</td>
        <td>
          <input style="    width: 100%;" id="slno1editinbound4" value="4" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundedititemname4" value="Sakthi - Chicken Masala" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditoldstock4" value="20" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditnewstock4" value="10" readonly="">
        </td>
        <td>
        <input style="    width: 100%;" id="stockinboundedittotalstock4" value="30" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="inboundeditqty4">
        </td>
        <td>
          <button style="background: #fdd110; width: 100%;" id="stockinboundeditditbut4">EDIT</button>
        </td>
      </tr>
      <tr>
        <td style="display:none;">tmcsubctgy_2</td>
        <td>
          <input style="    width: 100%;" id="slno1editinbound5" value="5" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundedititemname5" value="Goat Bones - Regular Soup Pack" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditoldstock5" value="0" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="stockinboundeditnewstock5" value="10" readonly="">
        </td>
        <td>
        <input style="    width: 100%;" id="stockinboundedittotalstock5" value="10" readonly="">
        </td>
        <td>
          <input style="    width: 100%;" id="inboundeditqty5">
        </td>
        <td>
          <button style="background: #fdd110; width: 100%;" id="stockinboundeditditbut5">EDIT</button>
        </td>
      </tr>
      </table>
    </table>
    
    <button onclick="readingTable()">View table as json array</button>
    <span id="demoSpan"></span>

what i have

1.here i have been displaying some data's inside '' tag inside ''

2.Then i got data as json arrays using javascript

What I needed

  1. now I have to print values from the only sl.no, item name and qty in a printer with A4 sheet size using javascript

for example

sl.no itemname qty
1 fish 2
2 chicken 2
3 goat 2
4 crap 2

*have to print like this from my table in a printer using javascript *i have to print in printer in the example format

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.