Turn uppercase characters of an entry into lowercase characters

1

I have this simple form and a jquery code that automatically fills in the 'email' field with the first name of the 'name' field and adds '@domain.com' to form an email address. How do I furthermore make the uppercase characters of the 'name' field in lowercase but only in the 'Email' field?

jquery:

$(window).load(function(){
  $("input[name=nome]").change(function () {
      var nome = $(this).val();
      var pEspaco = nome.indexOf(' ');
      var nomeFinal = nome;
      if (pEspaco != -1) {
          nomeFinal = nome.substr(0, pEspaco);
      }
      $("input[name=email]").val(nomeFinal + "@dominio.com.br");
  });
}); 

html:

        <form name="campos" method="post" action="<?=$PHP_SELF?>"> 
            <label>
                <span>Nome:</span>
                <input type="text" name="nome"  placeholder="" /><br>
            </label>
            <label>
                <span>Cargo:</span>
                <input type="text" name="cargo" placeholder="" /><br>
            </label>
            <label>
                <span>Celular:</span>
                <input type="text" name="celular" placeholder="Exemplo: 44 9876 9876" /><br>
            </label>
            <label>
                <span>e-mail:</span>
                <input type="text" name="email" placeholder="" /><br>
            </label>
            <input type="hidden" name="acao" value="enviar" />
            <button type="submit" class="envio" title="Enviar mensagem"></button> 
        </form>
    
asked by anonymous 22.06.2014 / 21:27

1 answer

1

You can use the method .toLowerCase () that is native to JavaScript.

It would look like this:

$("input[name=email]").val(nomeFinal.toLowerCase() + "@dominio.com.br");

You can simplify it a bit and use it like this:

$(window).load(function () {
    $("input[name=nome]").change(function () {
        var partes = this.value.split(' ');
        var email = partes[0];
        $("input[name=email]").val(email.toLowerCase() + "@dominio.com.br");
    });
});

If you want the last name, you can use var email = partes[partes.length - 1];

Example: link

    
22.06.2014 / 21:29