473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1956
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paweł | last post by:
I'm desinging a graphical interface and I frequently take advantage of the double click event. Unfortunately in most browsers double clicking also involves selecting and I would like to avoid that...
1
by: newcomer | last post by:
I have a javascript index that is similar to the one in the Windows help. It has a text field that allows the you to type text and it finds the closest item in the list below the text field. The...
2
by: Julian Jordan | last post by:
Hi I'm trying to write a system in which you can highlight some text in a form box, click a button (or press a key combination) and the text highlighted gets surrounded by a given html tag. ...
1
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting -1 value, eventhough 1000 of records are selected....
1
by: orekinbck | last post by:
Hi There I have a datagrid whose main purpose in life is to provide a nice way for users to make a single choice from a list. The grid is read only, single row select and has its data source as...
0
by: Benny Raymond | last post by:
I have a list view and a button that turns the currently selected item's ForeColor to SystemColors.GrayText The problem I'm having is that when the user clicks in white space, the item becomes...
2
by: Derek Vincent | last post by:
Using Visual Studio.net 2003 to create an aspx web form I am having a problem selecting an item from DropDownListBox with id= ListBoxStudies. I can see the items from the bound database table but...
2
by: Abubakar | last post by:
Hi, In a normal Windows.Forms.TextBox control, I want to be able to select a text (ie highlight, this is by default possible) and than be able to drag that text through my mouse pointer to another...
4
by: darrel | last post by:
I have a DDL list along these lines: item value="1" text="a" item value="2" text="b" item value="3" text="c" item value="2" text="d" item value="2" text="e" item value="1" text="f" item...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.