onSelect event of TEXTAREA (was: Re: [OFFTOPIC] Two newbie Mozilla questions...)

2003-09-17 Thread Omer Zak
By googling on textarea onSelect, I found:
1. http://www.firehouse58.com/tools/JSBook/Events/onselect.htm
  No mention of selectionStart or selectionEnd.

2. http://www.devguru.com/Technologies/ecmascript/quickref/event.html

  Description of events, in general.

3. 
http://www.devguru.com/Technologies/ecmascript/quickref/evhan_onselect.html

  Describes the onSelect event handler.  There are two properties
  of the event:
  type - the event type
  target - the object to which the event is being sent
4. 
http://www.tek-tips.com/gpviewthread.cfm/qid/549806/pid/216/lev2/4/lev3/32

  Insertion of text in middle of textarea - I couldn't figure out
  how to apply it to my case.  It may have been IE-specific (I need
  code which works on Mozilla).
I also tried the Mozilla DOM Inspector, but I don't know how to catch
the event object created when I select a substring in order to inspect
its attributes.
All this stuff seems to be documented (if at all) only in high priest
experts' areas in the WWW. :-(
I'm continuing to google for more keywords, but in the meanwhile
if anyone stands up and shouts the solution, this will be appreciated.
--- Omer
My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html
Ilya Konstantinov wrote:

On Monday 15 September 2003 18:33, Omer Zak wrote:
 

You mean their graphical position in (x,y), or you mean the position
within the text?
 

I mean the position within the text.  I couldn't care less about the
graphical position.
   

Try reading the selectionStart and selectionEnd properties of the 
HTMLTextArea object. To modify the selected range, use HTMLTextArea's 
setSelectionRange(start,stop) function. This is probably Mozilla-only API 
(not in the W3C DOM2 HTML). For the Microsoft version of this, http://
msdn.microsoft.com.

For those kinds of things, Mozilla's DOM Inspector (Tools | Web Development | 
DOM Inspector) is infinitely useful. Simply load your page inside it, point 
at any object and see its properties. By switching the right pane's mode, you 
can see the attributes, the CSS properties, the Javascript properties (and 
methods) and much more.
 



=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]


Re: onSelect event of TEXTAREA (was: Re: [OFFTOPIC] Two newbie Mozilla questions...)

2003-09-17 Thread Oded Arbel
On Thursday 18 September 2003 00:14, Omer Zak wrote:


 4.
 http://www.tek-tips.com/gpviewthread.cfm/qid/549806/pid/216/lev2/4/lev3/32

Insertion of text in middle of textarea - I couldn't figure out
how to apply it to my case.  It may have been IE-specific (I need
code which works on Mozilla).

Don't understand what's the big deal about. haven't read the above document, 
but if I'd want to replace selected text in a text area, I'd probably do 
something similar to this minimalistic test case (works in Mozilla, doesn't 
in konqi. don't know much about anything else):

htmlheadscript
function eventer(e) {
if (e.type != select) {
alert(not onselect);
return;
}
var mytext = replaced;
var a = e.target.selectionStart;
var b = e.target.selectionEnd;
var val = e.target.value;
e.target.value = val.substring(0,a) + mytext + val.substring(b);
}
/script/headbody
form
textarea id=testy cols=40 rows=10 onselect=eventer(event);
This is a long text from which I'm going to select
/textarea
/form/body/html

-- 
Oded


=
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word unsubscribe in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]