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

when I will type the first row 3 input box then those values are shown in the display name input box

when I will type the first row 3 input box then those values are shown in the display name input box.

enter image description here

var output = $('.keyupDisplay');

    
    $('.keyupName').keyup( function() {   
        output.val(function () {
            return $('.keyupName').map(function () {
                return this.value;
            }).get();
        });
    });

It is shown on the display input box but shows with "," separation. Like Mr,Motalib,Hossain
I need the result like this Like Mr Motalib Hossain

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

>Solution :

  • Use join
  • Cache the fields
  • Also no need to use a function inside the val
  • Use input since it also handles paste
  • Lastly, don’t name a field after what you decided to use to interrogate it. As we see it can change
const $displayName = $('.displayName')
const $names = $('.personName').on('input', function() {
  $displayName.val(
    $names
    .map(function() { return this.value; })
    .get()
    .join(' ')
  )
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Names: <input type="text" id="title" class="personName" />
<input type="text" id="firstName" class="personName" />
<input type="text" id="lastName" class="personName" />
<br/>
<input type="text" class="displayName" />
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