469,602 Members | 1,984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Selecting text so it STAYS selected.

I have a textarea and some buttons. The buttons apply functions to
the text the user selects, i.e. the good old "wrap with a tag"
thing we all have seen in 100 different editors.

Trouble is, when I click the button, the selected text gets
unselected. Select some text in the textbox and click -anywhere-
and the text unselects.

I want that text to stay selected!

Don't you?

How?
Jul 23 '05 #1
7 1770
Ivo
"Razzbar" wrote
I have a textarea and some buttons. The buttons apply functions to
the text the user selects, i.e. the good old "wrap with a tag"
thing we all have seen in 100 different editors.

Trouble is, when I click the button, the selected text gets
unselected. Select some text in the textbox and click -anywhere-
and the text unselects.
I want that text to stay selected!


Try calling the function behind that button "onmousedown" instead of
"onclick", as seen in 100 different editors.
HTH
Ivo
Jul 23 '05 #2
"Ivo" <no@thank.you> wrote in message news:<40***********************@news.wanadoo.nl>.. .
"Razzbar" wrote
I have a textarea and some buttons. The buttons apply functions to
the text the user selects, i.e. the good old "wrap with a tag"
thing we all have seen in 100 different editors.

Trouble is, when I click the button, the selected text gets
unselected. Select some text in the textbox and click -anywhere-
and the text unselects.
I want that text to stay selected!


Try calling the function behind that button "onmousedown" instead of
"onclick", as seen in 100 different editors.
HTH
Ivo


Good, good... Now, what if I want to select some text like for a
search and replace within the selection? I select me text, then
I go down to an input field where I wants to put in the terms
of the s&r... click -anywhere- outside of the selected area,
and the selection unselects. Drat.
Jul 23 '05 #3
Ivo
"Razzbar" wrote
"Ivo" wrote
"Razzbar" wrote
I have a textarea and some buttons. The buttons apply functions to
the text the user selects, i.e. the good old "wrap with a tag"
thing we all have seen in 100 different editors.

Trouble is, when I click the button, the selected text gets
unselected. Select some text in the textbox and click -anywhere-
and the text unselects.
I want that text to stay selected!


Try calling the function behind that button "onmousedown" instead of
"onclick", as seen in 100 different editors.
HTH
Ivo


Good, good... Now, what if I want to select some text like for a
search and replace within the selection? I select me text, then
I go down to an input field where I wants to put in the terms
of the s&r... click -anywhere- outside of the selected area,
and the selection unselects. Drat.


Even clicking *in* the selected area unselects it. It 's the very nature of
selections. The flashing cursor in the search box indicating where the next
typed letter will appear is sort of a selection itself (with length 0) and
there can only be one selection at a page at any time.
Generally I think such behaviour should be left alone so users know what to
expect and don't get confused. In your case, you could try copying the
selected text to a separate (hidden) area so it is remembered while typing,
or fiddling with its background and text-colour to make it *appear*
selected. This would probably best be done "onmouseup".
HTH
Ivo
Jul 23 '05 #4
Ivo
"Ivo" wrote
"Razzbar" wrote
"Ivo" wrote
"Razzbar" wrote
> I have a textarea and some buttons. The buttons apply functions to
> the text the user selects, i.e. the good old "wrap with a tag"
> thing we all have seen in 100 different editors.
>
> Trouble is, when I click the button, the selected text gets
> unselected. Select some text in the textbox and click -anywhere-
> and the text unselects.
> I want that text to stay selected!

Try calling the function behind that button "onmousedown" instead of
"onclick", as seen in 100 different editors.
HTH
Ivo
Good, good... Now, what if I want to select some text like for a
search and replace within the selection? I select me text, then
I go down to an input field where I wants to put in the terms
of the s&r... click -anywhere- outside of the selected area,
and the selection unselects. Drat.


On second thoughts, after reading your question a bit more slowly, I think
the best approach is the easiest: first enter the search&replacement
strings, and then select the text. This will make perfect sense to your
users if you label your buttons properly.
Ivo
Even clicking *in* the selected area unselects it. It 's the very nature of selections. The flashing cursor in the search box indicating where the next typed letter will appear is sort of a selection itself (with length 0) and
there can only be one selection at a page at any time.
Generally I think such behaviour should be left alone so users know what to expect and don't get confused. In your case, you could try copying the
selected text to a separate (hidden) area so it is remembered while typing, or fiddling with its background and text-colour to make it *appear*
selected. This would probably best be done "onmouseup".

Jul 23 '05 #5
"Ivo" <no@thank.you> wrote in message news:<40***********************@news.wanadoo.nl>.. .
"Razzbar" wrote
> I want that text to stay selected!

Even clicking *in* the selected area unselects it. It 's the very nature of
selections. The flashing cursor in the search box indicating where the next
typed letter will appear is sort of a selection itself (with length 0) and
there can only be one selection at a page at any time.
Close. There can be only one selection per -client area- i.e. a textarea,
or an input field... etc. But if there are two textareas in a window, you
should be able to make a selection in both. Should be able to.
Generally I think such behaviour should be left alone so users know what to
expect and don't get confused.
Confusion is what I'm trying to prevent. It's more intuitive to select
the area, then enter the search and replacement, then click the button,
than enter, select, click. And the confusion I'm getting is that when
I do it the latter way, my selection disappears... "where am I?".
In your case, you could try copying the
selected text to a separate (hidden) area so it is remembered while typing,
or fiddling with its background and text-colour to make it *appear*
selected. This would probably best be done "onmouseup".


That works, but it makes the textarea "blink". Guess I can live with
that.

Thing is, I've researched this before, and seem to recall finding
discussions on this subject, and that there was some attribute that
could be set. That's what I'm looking for. Some attribute you can
set that tells the selection to stay selected when the user clicks
outside the client area.

But I think it's still gonna have to blink. User selects, program
grabs a copy of the selection, applys the function to the copy, then
slaps the processed copy into the selection area. Oh well. It's ugly,
but it works. I'm not a web designer, I'm a web programmer. If I
were a web designer, that would be unacceptable.
Jul 23 '05 #6
rh
gl***@potatoradio.f2s.com (Razzbar) wrote:
<snip>
Thing is, I've researched this before, and seem to recall finding
discussions on this subject, and that there was some attribute that
could be set. That's what I'm looking for. Some attribute you can
set that tells the selection to stay selected when the user clicks
outside the client area.


Possibly you are recalling - unselectable="on" - which allows an
action, e.g., response to a mouseclick, to be initiated on an element
without removing focus from an existing selection.

I believe this is an IE only feature which was added by MS to provide
support for WSIWYG editors (originally based on MSHTML).

../rh
Jul 23 '05 #7
Ivo
"Razzbar" wrote
"Ivo" wrote
there can only be one selection at a page at any time.
Close. There can be only one selection per -client area- i.e. a textarea,
or an input field... etc. But if there are two textareas in a window, you
should be able to make a selection in both. Should be able to.


Sais who? I tried in Mozilla and IE, and both allow one selection on a page
and one only. I thought at least IE would remember (but invisibly) a
selection in a framed page while another frame has focus so multiple
selections in one window would be possible with a frameset, but I just tried
and when focusing the next frame or textarea or similar either by clicking
or tabbing, the earlier selection is lost. Tabbing back does not get it
back. Simple.
IF I had two textarea's on a page with a selection in both and I started
typing, where would my letters appear?
It's more intuitive to select
the area, then enter the search and replacement, then click the button,
than enter, select, click.
I 'm not convinced. At first sight, this is probably true, but people can
get used to the most crazy stuff as long as they 're not worried about the
craze or just do it often enough.
In your case, you could try copying the
selected text to a separate (hidden) area so it is remembered while typing, or fiddling with its background and text-colour to make it *appear*
selected. This would probably best be done "onmouseup".


That works, but it makes the textarea "blink". Guess I can live with
that.


Blink? Live with that? Guess that reaffirms my earlier statement about
getting used to things.
Thing is, I've researched this before, and seem to recall finding
discussions on this subject, and that there was some attribute that
could be set. That's what I'm looking for. Some attribute you can
set that tells the selection to stay selected when the user clicks
outside the client area.
Such attribute would be new to me.
But I think it's still gonna have to blink. User selects, program
grabs a copy of the selection, applys the function to the copy, then
slaps the processed copy into the selection area. Oh well. It's ugly,
but it works. I'm not a web designer, I'm a web programmer. If I
were a web designer, that would be unacceptable.


That 's no excuse! Please think about what you are saying. Don't hide behind
your code, you have clients who are real people. You give the profession a
bad name this way. The designer and programmer and any related profession -
because the end users don't know or care to know who did what.
Ivo
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by newcomer | last post: by
2 posts views Thread by Derek Vincent | last post: by
2 posts views Thread by Abubakar | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.