Hi all,
I have a form with a button that allows you to create a link. I have it set up so that wherever a user has their cursor it will add the link to that spot. Also, if they select a portion of text, i.e. Google, and then click the link button, that selected text will be put in the Title field of the link creation form. The only think left to do is to be able to replace that selected word/s, i.e. Google, with the entire html of the link. So, someone selects Google, hits the link button, fills out the form, hits submit and the link <a href="www.google.com" target="_blank">Google</a> replaces the selected Google text.

Here is all that I have so far:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">

body {
	text-align:center;
}

#wrapper {
	margin-left:auto;
	margin-right:auto;
	width:600px;
	text-align:left;
}

#greybg {
	display:none;
	width:100%;
	height:100%;
	position:absolute;
	left:0px;
	top:0px;
	background:gray;
	filter:alpha(Opacity=50);
	opacity:0.5;
	-moz-opacity:0.5;
}

#popup {
	display:none;
	position:absolute;
	top:0px;
	left:50%;
	margin-left:-200px;
	width:400px;
	height:258px;
	z-index:1;
	background:white;
	text-align:center;
	padding-top:10px;
}

#inside_popup {
	width:250px;
	margin-left:75px;
	text-align:left;
	font-family:Helvetica, Arial, sans-serif;
	color:#333;
	font-size:11px;
}

#popup span {
	font-size:23px;
	color:#222;
}

#buttons {
	float:right;
	margin-right:10px;
}

.form {
font-size:13px;
background-color:#eee;
border:solid 1px #ccc;
padding:2px;
}
</style>
	<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.js"></script>
	<script type="text/javascript">
		$(document).ready(function () {
			$("#open_popup").click(function() {
				$("#popup").slideDown();
				$("#greybg").fadeIn();
			});
			$(".close_popup").click(function() {
				$("#popup").slideUp();
				$("#greybg").fadeOut();
			});
		});
		
		function createLink(linkUrl, linkTarget, linkTitle) {
			var linkReturned = '<a href=\'' + linkUrl + '\' target=\'' + linkTarget + '\'>' + linkTitle + '</a>';
			return linkReturned;
		}
		    
   		function selectText (textArea) {
			var selectedText = (textArea.value).substring(textArea.selectionStart,
textArea.selectionEnd);  
			if (selectedText!='') {
				return document.link_pop.link_title.value = selectedText;
			}
		}
		
		function sendText(formName,insertText) {
    		if (formName.setSelectionRange){ 
        		formName.value = formName.value.substring(0,formName.selectionStart) + insertText + formName.value.substring(formName.selectionStart,formName.selectionEnd) + formName.value.substring(formName.selectionEnd,formName.value.length); 
    		} 
    		else if (document.selection && document.selection.createRange) { 
        		formName.focus(); 
        		var range = document.selection.createRange(); 
       			range.text = insertText + range.text; 
   			} 
		}
		
		function clearFields() {
			document.link_pop.link_title.value = '';
			document.link_pop.link_url.value = 'http://';
			document.link_pop.link_target.value = '_blank';
		}
	</script>
</head>
<body>
	<div id="greybg"></div>
	<div id="popup">
		<span>Would you like to add a hyperlink?</span><br /><br /><br />
		<div id="inside_popup">
			<form name="link_pop">
				
				Link Text<br />
				<input type="text" name="link_title" class="form" size="30"></input><br /><br />
				URL<br />
				<input type="text" name="link_url" value="http://" class="form" size="30"></input><br /><br />
				
				Open link in:<br />
				<select name="link_target">
					<option value="_blank">New Window</option>
					<option value="_self">Same Window</option>
				</select><br /><br /><br />
				</div>
				<div id="buttons">
				<input type="button" class="close_popup" value="Cancel" onclick="clearFields()"></input>
				<input type="submit" class="close_popup" value="Add Link" onClick="sendText(document.form.text,createLink(this.form.link_url.value, this.form.link_target.value, this.form.link_title.value)); clearFields(); return false;"></input>
				</div>
			</form>
	</div>
	<div id="wrapper">
		<form name="form">
			<textarea name="text" cols="30" rows="20"></textarea>
			<input type="button" value="Link" id="open_popup" onClick="selectText(this.form.text)"></input>
		</form>
	</div>
</body>
</html>
Thanks for any help,

Matt