I have a input
, where the user types his / her full name from the following code:
<input type="text" id="fullname" name="fullname" title="fullname" maxlength="255" class="input-text fullname onestep" placeholder="Escreva o nome completo" onchange="saveNomeSobrenome($j(this).val())" />
By means of the saveNomeSobrenome()
function, I can separate only the last word entered by the user that I will save as last name, but I needed to separate the "rest" that he typed to save as a name. One difficulty I'm also having is to transform this function javascript
into jQuery
.
Function Code:
function saveNomeSobrenome(string){
var frase = string;
var palavras = frase.split(" ");
tamanho = palavras.length;
sobrenome = palavras[tamanho-1];
console.log(sobrenome);
}