How can I pass a jQuery selector to this function? It works fine this way:
$("input[name='this_field']").blur(function() {
var text = $(this).val();
if ( $("#repeat").val('') ) {
$("#repeat").val(text);
};
});
But when I try it this way;
function repopulateFields(target){
var text = $(this).val();
if ( $(target).val('') ) {
$(target).val(text);
};
}
$("input[name='this_field']").blur(function() {
repopulateFields("#repeat");
});
It doesn't work and throws an error. What's wrong here?