0

I am trying to auto-populate a text field based on the value of another input field.

The difference between other questions made in Stack Overflow, is:

  • PHP or JavaScript scripting language.
  • The auto populated field should be without accents (áéíóúñ), all characters must be in lowercase and separated with dashes.

As showed in this picture: Input field one (Titulo) and input field two (Titulo Alias)

Julian Moreno
  • 1,084
  • 3
  • 15
  • 30

3 Answers3

2
$(document).on('ready', function(){
    $('#titulo').keyup(function() {
        var replacements = {"á":"a", "é":"e", "í":"i", "ó":"o", "ú":"u", "ñ":"n", " ":"-"};
        val = $('#titulo').val().toLowerCase().split('');
        $.each(val, function(i,e){val[i] = replacements[e] ? replacements[e] : e;});
        $('#titulo-alias').val(val.join(''));
    });
});
animuson
  • 53,861
  • 28
  • 137
  • 147
arley.wilches
  • 36
  • 1
  • 3
0

$('#titulo-alias').val( $('#titulo').val().toLowerCase().replace(' ', '-') );

To remove accents take a look at Remove accents/diacritics in a string in JavaScript

Community
  • 1
  • 1
elclanrs
  • 92,861
  • 21
  • 134
  • 171
0
$('#titulo-alias').val( $('#titulo').val().toLowerCase().replace(' ', '-').replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u').replace('ñ', 'n') );
Leysam Rosario
  • 379
  • 2
  • 11
  • Sorry for the late responce. I havent really test this code before posting. Im on a rush that day. Anyway glad that your problem is solve. cheers! – Leysam Rosario Feb 08 '12 at 10:04