David wrote:
> I do not know Javascript and have not tripped over anything that looks
> promising to do this. What I need is the syntax (if this is even
> possible!) for the document.setSelection" command.
Well if the document object has a method named setSelection then the
syntax to call it is
document.setSelection()
if the method takes a string argument then you have the right syntax
already e.g.
document.setSelection('1234-3456-4567-5678');
But I don't think that is a syntax problem, it seems what you are after is
> What I want this to
> do is output the text where the cursor currently is.
the right object and the right method name. Those depend on the browser,
at least for some non-standardized stuff like text selection and its
manipulation.
As far as I know Safari so far has no API exposed to JavaScript to
manipulate the selection.
If they have one chances are they have tried to be compatible with an
existing API, MSIE/Win has one documented here:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_selection.asp>
So there you could do
if (document.selection && document.selection.createRange) {
document.selection.createRange().text = '1234-3456-4567-5678';
}
I do not have access to a Mac currently so you would need to try that
yourself.
Mozilla also has an API to manipulate the text selection but there are
different APIs there really, one exposed on text controls and one for
text rendered on the page. So with Mozilla you would need to know which
control you want to insert text into.
Example code is here:
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>
Again you would need to test that with Safari yourself.
--
Martin Honnen
http://JavaScript.FAQTs.com/