You can simplify it this way:
- Switch to using
.one()
to register your event handler so it only fires once. - Remove the intermediate variables and just process the string all at once
The code:
$('#article_title').one('change', function() {
$('#article_slug').val($(this).val().replace(/\s+/g, '-').toLowerCase());
});
Working demo: http://jsfiddle.net/jfriend00/XGjWA/