12-04-2008, 08:11 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Jan 2008
Posts: 24
Thanks: 13
|
Input-field with captured text falsely empties on click
The script captures body-text to a specified input-field by either left-clicking and dragging the mousepointer over or simply performing a double-click on it.
The problem: When text is entered manually into the input-field, it simply disappears when a neighbouring select-element is clicked. Why?
Another minor issue is that I would actually prefer to be able to limit the capturable area to a container with an id.
Although this code doesn't make use of a framework, I wouldn't mind a solution with JQuery or MooTools.
Code:
// Captures highlighted text within the document to a specified input-field.
var text = "";
// Captures all highlighted text.
function captureText()
{
// Sets text MSIE or Netscape active.
lookuptext = (document.all) ? document.selection.createRange().text : document.getSelection();
// Form name="research", input name="lookup"
document.research.lookup.value = lookuptext;
return TRUE;
}
// Initiate capture function
document.onmouseup = captureText;
if(!document.all) document.captureEvents(Event.MOUSEUP);
|
|
|
|