-1

I have a text box where we can enter some text, based on the input few more text boxes appear which are read only and prefilled with data.

Data in those fields are not in Title case, please suggest how can i convert that data in title case using only jquery.

The challenge here is, populated text boxes are read only hence not able to use any event like, onfocus, keyup, keydown, keypress.

When i use 'load' then the text boxes appears on loading of page without data.

mayank sharma
  • 63
  • 2
  • 2
  • 9

2 Answers2

0

If you want text to be uppercase you can do :

$("#yourTextBoxId").val().toUpperCase();
Quentin Roger
  • 6,410
  • 2
  • 23
  • 36
0

Here is a plunker

https://plnkr.co/edit/3tRw13KQ2HgpfwX7dJPx?p=preview

function titleCase(str) {
   var splitStr = str.toLowerCase().split(' ');
   for (var i = 0; i < splitStr.length; i++) {
       // You do not need to check if i is larger than splitStr length, as your for does that for you
       // Assign it back to the array
       splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);     
   }
   // Directly return the joined string
   return splitStr.join(' '); 
}


  $('#writtable').on('change',function(e){
    $('#pepe').val(titleCase($('#writtable').val()));
  })

The basic idea is im getting the input of a text and on change event updating the input readonly on the other. Hope it helps

jstuartmilne
  • 4,398
  • 1
  • 20
  • 30