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

Input paste long text split to other input (jquery)

I am new to HTML and jQuery. If I paste the long text to first input, I wanted it to be automatically split to other input (based on space). Is it possible to do it in jQuery? Please help.

This is the code:

https://codesandbox.io/s/kind-boyd-jnig1b?file=/index.html

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

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Static Template</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  </head>
  <body>
    <!-- if type this long text to first input ,
      Split long text to each input 
      based on space -->

    work pork dork bark crack shame
    <br />
    <input class="input" />

    <input class="input" />

    <input class="input" />
    <input class="input" />
    <input class="input" />
    <input class="input" />
  </body>
  <script>
    // A $( document ).ready() block.
    $(document).ready(function () {});
  </script>
</html>

>Solution :

  1. Split your input text based upon space.
  2. Loop between them to get each word on text box.

Example:

$(".input").keyup(function() {
  var arr = $(this).val().split(" ");
  $.each(arr, function(index, value) {
    $('input').eq(index).val(value)
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
work pork dork bark crack shame

<input class="input" />
<input class="input" />
<input class="input" />
<input class="input" />
<input class="input" />
<input class="input" />
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