textbox question

G

Guest

I have a user that when tabs to a textbox notices that the curser lines up
with the end of the current text entry if the textbox is in the multiline
mode. If the textbox is in the single line mode when tabing to it, the
entire entry is highlighted. The user would like the entire text entry to be
highlighted so they do not have to backspace and can just start typing if
they need to change the entry. Just wondering if there is a way to set this
up and still have the textbox in the multiline mode?
Thanks.
 
E

Elliot M. Rodriguez

Paul:

You can accomplish this with a little Javascript by handling the onFocus
event for the textbox.

Add this to your codebehind (C#):
this.YourTextBoxName.Attributes.Add("onFocus","javascript:DoHighlight(this.value);");

Then, in your HTML, inject the following:

<script language="javascript">
function DoHighlight(TextInBox)
{
if (TextInBox.length > 0)
{
document.Form1.YourTextBoxName.select();
}
}
</script>
 
G

Guest

Hi thanks for the information. I will give this a try. Something like this
might work for another problem I am working on. I have several controls and
when the page loads I have script that puts the focus on the top control.
The only problem is that about halfway down the page I have 2 dropdown list
boxes and when the user makes a selection I call a stored procedure and fill
the second dropdown box with values corresponding to that selection. The
page reload to populate the second dropdown box but the focus jumps back up
to the top control(since the page reloaded). In this case I would like the
focus to stay where it is at (first dropdown box in the middle of the page)
or go to the second dropdown box.
Thanks again.
--
Paul G
Software engineer.


Elliot M. Rodriguez" <"elliotrodriguez[s said:
Paul:

You can accomplish this with a little Javascript by handling the onFocus
event for the textbox.

Add this to your codebehind (C#):
this.YourTextBoxName.Attributes.Add("onFocus","javascript:DoHighlight(this.value);");

Then, in your HTML, inject the following:

<script language="javascript">
function DoHighlight(TextInBox)
{
if (TextInBox.length > 0)
{
document.Form1.YourTextBoxName.select();
}
}
</script>


I have a user that when tabs to a textbox notices that the curser lines up
with the end of the current text entry if the textbox is in the multiline
mode. If the textbox is in the single line mode when tabing to it, the
entire entry is highlighted. The user would like the entire text entry to be
highlighted so they do not have to backspace and can just start typing if
they need to change the entry. Just wondering if there is a way to set this
up and still have the textbox in the multiline mode?
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top