1

I want to title case form inputs using the humanize library and Jquery. So far I have this:

$("#FirstName,#LastName").blur(function () {
    Humanize.titleCase( $(this) )
});

but it gives me an error:

humanize.min.js:2 Uncaught TypeError: n.split is not a function
    at o (humanize.min.js:2)
    at Object.titleCase (humanize.min.js:2)
    at HTMLInputElement.<anonymous> (<anonymous>:3:14)
    at HTMLInputElement.dispatch (jquery-2.2.4.min.js:3)
    at HTMLInputElement.r.handle (jquery-2.2.4.min.js:3)
Emrys
  • 17
  • 4

1 Answers1

1
Humanize.titleCase( $(this) )

should be

Humanize.titleCase( $(this).val() );

Update after @vlaz comment

the full code will be something like

$("#FirstName,#LastName").blur(function () {
    $(this).val( Humanize.titleCase( $(this).val() ) );
});
kiranvj
  • 22,650
  • 5
  • 51
  • 69
  • Unless these are, say, `span`s or `div`s, in which chase it'd be `.text()`. And even then, the result would need to be written back to where it came from, else the callback effectively does nothing. – VLAZ Sep 19 '18 at 04:50
  • 1
    Yes, but normally `span` and `div`s will not have `blur` event unless they have tabindex 0 – kiranvj Sep 19 '18 at 04:55