Titlecase in Fields

I have a multichoice field with option selected to add a new option. However often user enter lower case option and I want Titlecase data. I’ve played around with some JS to make this happen without luck.

Any ideas? Its also in a modal. Below is one attempt.

$(document).on(‘knack-scene-render.scene_36’, function(event, scene, record) {
// Get the input field element
// Function to convert input to title case
// Function to convert input to title case
function convertToTitleCase(input) {
// Split the input into an array of words
const words = input.toLowerCase().split(" ");

// Convert the first character of each word to uppercase and join them back
const titleCaseText = words.map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");

return titleCaseText;


// Get all input fields on the webpage
const inputFields = document.querySelectorAll(“#kn-add-option .kn-input input[type=‘text’]”);

// Attach event listener to each input field
inputFields.forEach(inputField => {
inputField.addEventListener(“input”, function() {
// Get the current input value
const inputValue = inputField.value;

  // Convert the input value to title case
  const titleCaseValue = convertToTitleCase(inputValue);

  // Update the input field value with the title case value
  inputField.value = titleCaseValue;


Hi @PhilWesley67576, here’s what you need:

$(document).on('knack-view-render.any', function (event, view, data) {

  /*Replace field_XX with your field ID*/
  $('#field_XX').keyup(function() {
    var inputValue = $(this).val();
    var formattedValue = toTitleCase(inputValue);


function toTitleCase(str) {
  return str.toLowerCase().replace(/(?:^|\s)\w/g, function(match) {
    return match.toUpperCase();

This will result in the following, where I am only using lowercase letters.

Hope that helps!

Hi Stephen

Thanks for this, and excellent solution. However in this case is a modal popup with an input in a form as below, so no field, might try using the “Input” element.

<div class="kn-input"><input type="text" autocomplete="off"></div>
<div class="kn-submit"><input type="submit" value="Submit"></div>

Heck… I so over thought this LOL ermm simply CSS

    input {
      text-transform: capitalize;