Hi,
Code below replaces selected number with an URL given by the user. It doesn't work the way it supposed to do. If I select second 2 to make it an URL, it makes first 2 an URL instead. How do I solve this problem?
Thanks in advance
<script language="JavaScript">
function makeURL(content){
var selected = (content.value).substring(content.selectionStart, content.selectionEnd);
var url = prompt("Please insert URL here:");
content.value = content.value.replace(selected, url);
}
</script>
<form name="form1" action="next.php" action="POST">
<textarea name="textareaContent" rows="10" cols="50">1, 2, 3, 2, 1.</textarea>
<br />
<input type="submit" name="submitButton" value="SEND" />
</form>
<br />
<a href="#" onClick="makeURL(form1.textareaContent)">Make it URL</a>