Seems simple enough; at least in my browser (Chrome) dragging a link into a input/textarea and having it populate with the URL that the anchor references is default functionality; therefore the following should do the job.
$("input").change(function() {
if($(this).val().substring($(this).val().length-3, $(this).val().length) == 'jpg') {
$("a img").attr('src', $(this).val())
} else {
$("a").attr('href', $(this).val())
}
})
Obviously you'd want to expand the code to support further filetypes and I'm sure there are better way to identify whether the URL refers to an image or not, but this is a good starting point.
If this doesn't serve your exact needs you might want to consider what event to bind on the input box in question; focus could also be a viable option?