Reputation: 1104
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:
As showed in this picture:
Upvotes: 0
Views: 1216
Reputation: 36
$(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(''));
});
});
Upvotes: 2
Reputation: 369
$('#titulo-alias').val( $('#titulo').val().toLowerCase().replace(' ', '-').replace('á', 'a').replace('é', 'e').replace('í', 'i').replace('ó', 'o').replace('ú', 'u').replace('ñ', 'n') );
Upvotes: 0
Reputation: 94101
$('#titulo-alias').val( $('#titulo').val().toLowerCase().replace(' ', '-') );
To remove accents take a look at Remove accents/diacritics in a string in JavaScript
Upvotes: 0