I have a problem here. I just started learning with Yii2
and I need to capitalize first letters
of my entry form (it's name and surname). I'm doing this with JS, but somehow my code does not work and it didn't printing any results. Could someone help me to solve this problem and tell me what I'm doing wrong?
Here is my code:
function entryForm(name, surname) {
this.name = $(name);
this.surname = $(surname);
var self = this;
/*
* Capitalizes first letter of users entered name and surname
*
* @param string input
*/
this.capitalizeName = function(input) {
var name = input.val();
name = name.toLowerCase().replace(/(^|\s)[a-z]/g, function(letter) {
return letter.toUpperCase();
})
input.val(name);
}
var entryForm = new entryForm('#employee-name', '#employee-surname');
$(document).ready(function() {
/*
* Executes named function
*/
$('#employee-name, #employee-surname').change(function() {
entryForm.capitalizeName($(this));
})
})
}