0

I’m setting up a new server, and want to support UTF-8 fully in my web application.How to have the capital letter of every word in a row? When I enter text, I want each word to have a capital letter example: input: daniel is big king output: Daniel Is Big King. I don't know what I'm missing example: input: daniel is big king output: Daniel is big king. Only the first word has a large initial letter

testfunction = () => {
  var inputtext = document.getElementById('inputtext').value;
  var operation = inputtext.charAt(0).toUpperCase() + inputtext.slice(1);
  console.log(operation);
}
<input type="text" id='inputtext'>
<button onclick="testfunction()">
Try it
</button>
Rohny99
  • 25
  • 5

1 Answers1

1

You can use the css property text-transform: capitalize;

testfunction = () => {
  var inputtext = document.getElementById('inputtext').value;
  var operation = inputtext.charAt(0).toUpperCase() + inputtext.slice(1);
  document.getElementById('testview').innerHTML = operation;
}
#testview {
  text-transform: capitalize;
}
<input type="text" id='inputtext'>
<button onclick="testfunction()">
Try it
</button>
<br>
<span id='testview'>
</span>
R3tep
  • 12,512
  • 10
  • 48
  • 75
  • For display purposes this works, however if OP plans to use that value in JavaScript (store it, pass it, etc), it's worth noting that it will remain unchanged. – Tyler Roper Aug 14 '19 at 15:06
  • @TylerRoper He can reuse this css property when he want to show it – R3tep Aug 14 '19 at 15:07