form.element.value from selected text

M

Martin Nadoll

hello

is it possible, to have a <textarea> element in a form, to write text into
that, select a part of that text and with a button to trigger a function
<button... onClick="showSelected('parameter???')">
that can work with the selection.

For example:
function showSelected(param???) {
// maybe:
my_Selected_Part_Of_Textarea=param???;
// or:
my_Selected_Part_Of_Textarea=document.forms['myForm'].elements['myTextarea'].selectedvalue;
alert(my_Selected_Part_Of_Textarea);
}

Does javascript capture, what is selected in that <textarea> element?

Thanks for any idea about that,
Martin Nadoll
 
M

Martin Honnen

Martin said:
Does javascript capture, what is selected in that <textarea> element?

With Mozilla and I think Opera and Safari too the browser exposes two
properties named
selectionStart
selectionEnd
on input type="text" and on textarea element objects. So you can access
textarea.value.substring(textarea.selectionStart, textarea.selectionEnd)

IE has a different API for the complete selection in the document,
whether it is inside of a control or whether it is inside of normal
elements like p or div. There you can use
document.selection.createRange().text
to get the selected text.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top