Lukas Oppermann
Lukas Oppermann

Reputation: 2938

jQuery copy input val to other input and replace characters

I got the following problem and I did not find any solution.

I have to input fields: "label" and "url".

When you write something into the label field it should be duplicated into the url field. This works like a charm, but I need the url field to be (url_encoded or sanitized) rather it would like to replace special characters with customized ones e.g. 'ä' with 'ae' or ' ' with '+'. I figured I could just use a RegEx function to replace things like ä or é but I do not get it right.

Can you tell me how I can do it?

Thanks in advance.

Upvotes: 1

Views: 543

Answers (2)

artyom.stv
artyom.stv

Reputation: 2164

var h = function(){
    var self = this;
    setTimeout(function(){ $("#url").val(encodeURIComponent($(self).val())); }, 5);
};
$("#label").change(h).keydown(h);

Upvotes: 1

Shaz
Shaz

Reputation: 15877

Take a look at this: http://jsfiddle.net/Shaz/bwKZt/

Upvotes: 1

Related Questions