if you select some text in element id "bentry1" and call this it will wrap html links around the selection

Code:
function addlink() {
	var link=prompt("Paste link here","");
	if (link) {
		var b1s=document.getElementById("bentry1");
		var b1=document.getElementById("bentry1").value;
		var tt1 = b1s.value.substr(0, b1s.selectionStart);
		var tt2 = b1s.value.substr(b1s.selectionStart, (b1s.selectionEnd - b1s.selectionStart));
		var tt3 = b1s.value.substr(b1s.selectionEnd, b1.len);
		var tt2='<a href="'+link+'">'+tt2+'</a>';
		document.getElementById("bentry1").value=tt1+tt2+tt3;
	}
}