0

I have dynamic table with data from the server, and in the table I have some textareas. Now, I would like to check when the user starts writing in one of them and when the user deletes all the text in all of them.

I tried something like this but I cant get it to count and its taking the value of only on textarea:

<?php foreach ($arr_cases as $cases) : ?>
<tr>
  <td>
     <div id="wrapper">
       <textarea class="manuf_comment" name="manuf_comment[<?php echo $cases["Dev_Id"] ?>]" oninput="display_hide_save_button()" placeholder="Comment here" maxlength="500" rows="2" cols="50"><?php echo $cases["manuf_comment"]; ?></textarea>          
     </div>
  </td>
</tr>
<?php endforeach; ?>

the javascrit function that I am calling:

   function display_hide_save_button(cb) {
        var on_input_text = document.getElementsByClassName("manuf_comment");                     
        if (on_input_text.length > 0) {
            alert("The user started writting")
        } else {
            alert("The user has erased everything")
        }
    }
showtime
  • 1
  • 1
  • 17
  • 48
  • Your JS checks if there is any textarea in page with that class, not it's contents. You need to loop `on_input_text` and do `if (inputText.value.length > 0)` – Justinas Jul 02 '20 at 14:22
  • @Justinas I tried to getelementbyid but doesn't work at all, that's why I use byclass because that's the only one that actually gets called – showtime Jul 02 '20 at 14:33

0 Answers0