-1

I would need a Custom JavaScript for a WordPress form, converting upper cases to lower cases. I found some entries here in the community, but not the one I need.

What should be converted ? For example I get a form entry 'PETER' and I want that the first digit 'P' stays in upper cases and the rest should be converted to lower cases. From 'PETER' to 'Peter'

Who can give a helping hand, please ? Thanks

Go-
  • 1

1 Answers1

0

You can get the sting first char with str[0], the other parts sliced with -1 argument.

const name = "PETER";

function PETERToPeter(str) {
  return str[0].toUpperCase() + str.slice(1).toLowerCase();
}

const nameChanged = PETERToPeter(name);

console.log(nameChanged);
exphoenee
  • 465
  • 4
  • 11
  • Thanks a lot, exphoenee. I added the JS code. Need to check deeper later, nothing changes after I insert anything in the form fields – Go- Oct 22 '22 at 17:18
  • Share your code for more help. I don't know really what you did.... – exphoenee Oct 23 '22 at 18:35