Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get this HTML Table textarea's value using JS?

I’ve tried some suggestions, but no success so far.

I’m getting null when trying to get this textarea value while going through the table and I don’t know exactly why:

function savePo(user, origin) {
  user = 'user';
  origin = 'Trim';


  let date = new Date();
  options = {
    year: 'numeric',
    month: 'numeric',
    day: 'numeric',
    hour: 'numeric',
    minute: 'numeric',
    second: 'numeric',
    hour12: false,
    timeZone: 'CST'
  };

  let timeStamp = new Intl.DateTimeFormat('en-US', options).format(date).toString();
  timeStamp = timeStamp.replace(",", "");

  const tableRows = document.querySelectorAll("#tableRows tr");

  let tableData = [];
  if (origin == 'Trim') {
    tableData = [...tableRows].map(r => {
      let td = r.querySelectorAll("td");
      return [...td].map((c, j) =>
        j == 2 ? c.value : //THIS IS THE LINE WHICH IS NOT WORKING PROPERLY
        j == 7 ? c.querySelectorAll('input[type="checkbox"]')[0].checked :
        j == 6 ? c.innerText :
        c.querySelector('input').value)
    });
    console.log('Table Data: ' + tableData)
  }
}

Here is the Fiddle in case you feel like pointing where the flaw is.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Appreciate it!

>Solution :

To get the value of a textarea element, instead of innerText of the parent element use value of such textarea element.

const text = document.querySelector('td textarea').value
console.log(text)
<table>
  <tr>
    <td>
    <textarea name="articuloField" id="articulo" rows="2" cols="65" wrap="soft">Testing the textarea value field which never seems to work!!!!!!!!!!</textarea>
    </td>
  </tr>
</table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading