Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #9781

Re: Input Controls

Date 2011-12-30 12:57 +0100
From Martin Honnen <mahotrash@yahoo.de>
Organization Liberty Development
Newsgroups comp.lang.javascript
Subject Re: Input Controls
References <sk5qf7h79vi3f5v6u1rnapq4t5e5020h8d@4ax.com>
Message-ID <4efda717$0$7614$9b4e6d93@newsspool1.arcor-online.net> (permalink)

Show all headers | View raw


Gene Wirchenko wrote:

>    1) Position to a particular point in a control's value.  For
> example, if entering a date, it could be much more user-friendly if,
> when the control gets focus, the cursor were positioned just before
> the days as in:
>            201112@29
> where the at-sign represents the cursor.  (In my app-to-be, the date
> is usually in the current month, but not always.)
>
>    2) I want to be able to programmatically select part of an input
> control value.  e.g.  Click on some part of the sentence below and
> have that word and only that word selected
>            The quick, brown fox jumps over the lazy dog.
>                        ^
>            The quick, brown fox jumps over the lazy dog.
>                       ===== selected
> or have the day of a date selected but not the rest.

For most browsers with the exception of IE 8 and earlier text controls 
(like input type="text" and like textarea elements) expose properties
   selectionStart
   selectionEnd
and a method
   setSelectionRange(startPos, endPos)
you can use, see 
https://developer.mozilla.org/en/DOM/HTMLTextAreaElement#Properties 
respectively 
http://msdn.microsoft.com/en-us/library/ff974768%28v=VS.85%29.aspx.

With earlier IE versions you can manipulate the selection with 
http://msdn.microsoft.com/en-us/library/ms535869%28v=VS.85%29.aspx, see 
also the link in a previous response.


-- 

	Martin Honnen --- MVP Data Platform Development
	http://msmvps.com/blogs/martin_honnen/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Input Controls Gene Wirchenko <genew@ocis.net> - 2011-12-29 18:11 -0800
  Re: Input Controls Norman Peelman <npeelmandog@cfl.rr.com> - 2011-12-30 06:40 -0500
  Re: Input Controls Martin Honnen <mahotrash@yahoo.de> - 2011-12-30 12:57 +0100
  Re: Input Controls "Mel Smith" <med_cutout_syntel@aol.com> - 2011-12-30 10:49 -0700
  Re: Input Controls RobG <rgqld@iinet.net.au> - 2011-12-31 15:21 -0800

csiph-web