PDA

View Full Version : JavaScript & DHTML: Cut/Copy & Paste Selected text ONLY in IE 6



deadstone
02-08-2005, 09:25 AM
Hi,

I have a form with several fields, and have built a right-click context menu for field editing operations.

For example,I use this function for 'Cut':
/// CUT FN ///
// rcMenus.Ofield returns the field that was right-clicked on to
// show the menu
function fnCut(){
var oSource=rcMenus.oField;
event.returnValue = false;
bResult = window.clipboardData.setData("Text",oSource.value);
oSource.innerText = "";
}

and this code for Paste
/// Paste fn ///
// rcMenus.Ofield returns the field that was right-clicked on to
// show the menu
function fnPaste() {
event.returnValue = false;
var oTarget=rcMenus.oField;
oTarget.value = oTarget.value + window.clipboardData.getData("Text");
}

... so my problem is that it cuts the entire contents of the input rather than just the selected text.

This is because I am using the value of the field that I am cutting from.
So what property of the INPUT (TYPE=TEXT) HTML element exposes the selected text only so I can add just that to the clipboardData object?
I tried using the selection object but that seems to only work on the document level, rather than the element level.

thanks for any tips or advice

Philip