I think that solves your problem, he takes the line break and mounts a array
with 4 positions and add the values in the others </textarea>
, paste text and focus to the other element:
$(document).ready(function() {
$("#tmestre1").on("change", function() {
const texto = $("#tmestre1").val().split("\n");
$("#tmestre4").val(texto[3]);
$("#tmestre3").val(texto[2]);
$("#tmestre2").val(texto[1]);
$("#tmestre1").val(texto[0]);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea rows="5" cols="33" id="tmestre1"></textarea>
<textarea rows="5" cols="33" id="tmestre2"></textarea>
<textarea rows="5" cols="33" id="tmestre3"></textarea>
<textarea rows="5" cols="33" id="tmestre4"></textarea>
Yes, it is possible. Using the event
onpaste
, it is possible to capture the data that is "pasted" through Ctrl + V (or Command + V), with this, it is possible to separate the paragraphs and fill the input.– Valdeir Psr
Thank you! My problem was in detecting the line break. Thanks!!!
– Matheus Soares
and if you have more than 4 paragraphs?
– user60252