I'm trying to prepare a Javascript function that changes the "selected text" url to fully active HTML Hyperlinks.
My HTML code is:
<html>
<body>
<textarea id="my_input" cols="32" rows="16" textToDisplay>Some text with https://www.google.pl/?gws_rd=ssl for simple WYSIWYG function</textarea>
<input type="submit" value="[to url]" onclick="make_url('my_input')" />
</body>
</html>
My js function:
<script>
function make_url(my_input) {
var my_input=document.getElementById(my_input);
var selected_text=window.getSelection();
my_input.value=my_input_begin.value + '<a href="'+selected_text+'">'+ selected_text +'</a>' + my_input_end.value;
}
</script>
But after selecting https://www.google.pl/?gws_rd=ssl
and pressing submit I get empty HTML Hyperlinks. What is wrong? window.getSelection()
/ document.getSelection()
doesn't get the selected text.
The second question is - how to get my_input_begin.value
and my_input_end.value
or replace only "selected" part of my <textarea>
entry?