-1

I have a modal input with 2 fields. One is the text input for the full name and the second is a disabled field to get the live result. The result is the Capitalized letter of each word in the input text field 1. I have no clue on how to go about doing this, any thoughts or ideas?

$(function() {
                var $src = $('#inputClientName'),
                  $dst = $('#disabledinputClientCode');
                $src.on('input', function() {
                  $dst.val($src.val());
                });
              });

//This is what I tested:
//match(/(\b\S)?/g).join("").toUpperCase()

This code lets me copy the input into the destination text block. I tried using the test code above and could not get the desired result. Please help.

Kumar
  • 5
  • 2
  • 1
    Welcome to Stack Overflow! Visit the [help], take the [tour] to see what and [ask]. Please first ***>>>[Search for related topics on SO](https://www.google.com/search?q=javascript+capitalize+name+site%3Astackoverflow.com)<<<*** and if you get stuck, post a [mcve] of your attempt, noting input and expected output using the [`[<>]`](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Dec 13 '21 at 07:08

2 Answers2

0

I think easiest would be to use a Regex. Something like this should do the job:

const input = "This Is Some Test";
const output = input.match(/[A-Z]/g);

console.log(output);
Behemoth
  • 5,389
  • 4
  • 16
  • 40
  • How would I incorporate you sample code into-``````````````````````````````````````````````````````````````````````````````````````````````````$(function() { var $src = $('#inputClientName'), $dst = $('#disabledinputClientCode'); $src.on('input', function() { $dst.val($src.val()); }); ); `````````````````````````````````````````````````````````````````````````````````````````` – Kumar Dec 13 '21 at 13:06
0

You can use CSS to do that. There is a CSS prop: text-transform (docs here). When you add text-transform: capitalize; to the styling of the input it will capitalize each word. Now all you have to do is set the value of the first input to be equal to the value of the second input.

Gabriel Lupu
  • 1,397
  • 1
  • 13
  • 29