10
I have a input
, where the user enters his or 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())" />
Through the function saveNomeSobrenome()
, I can only separate the last word typed by the user that I will save as last name, but I needed to separate the "rest" that he typed to save as name. One difficulty I’m also having is transforming that function javascript
in jQuery
.
Function code:
function saveNomeSobrenome(string){
var frase = string;
var palavras = frase.split(" ");
tamanho = palavras.length;
sobrenome = palavras[tamanho-1];
console.log(sobrenome);
}
Why don’t you just put two input for first and last names? João Pedro da Silva for example would be wrong. The guy’s name is not "João Pedro da". Better to ask the user for a name than to guess.
– user7349055