Questions tagged [textbox]

A textbox is a graphical user interface element which allows for simple input text, usually only a single line of text.

A text box, text field or text entry box is a kind of widget used when building a graphical user interface (GUI). A text box's purpose is to allow the user to input text information to be used by the program. User-interface guidelines recommend a single-line text box when only one line of input is required, and a multi-line text box only if more than one line of input may be required. Non-editable text boxes can serve the purpose of simply displaying text.

A typical text box is a rectangle of any size, possibly with a border that separates the text box from the rest of the interface. Text boxes may contain zero, one, or two scrollbars. Text boxes usually display a text cursor (commonly a blinking vertical line), indicating the current region of text being edited. It is common for the mouse cursor to change its shape when it hovers over a text box.

Wikipedia article: https://en.wikipedia.org/wiki/Text_box

Alternatively text box referred to as a text field, a text box is a section of a page that enables a user to enter text. Text boxes are often used on the Internet for pages that require input from a user. Below are some examples of text boxes you are likely to encounter.

One-line text box

A one-line text box is often used when only a few words, such as a name, are required.

single line

Scrolling text box

A scrolling text box allows a user to enter lots of data and usually scroll up, down, left, or right to view the text in the box.

multi line

In HTML, a textbox can be made with either <input type=text></input> or <textarea></textarea>.

12672 questions
672
votes
41 answers

How do I make a textbox that only accepts numbers?

I have a windows forms app with a textbox control that I want to only accept integer values. In the past I've done this kind of validation by overloading the KeyPress event and just removing characters which didn't fit the specification. I've looked…
Mykroft
  • 13,077
  • 13
  • 44
  • 72
602
votes
29 answers

Calculate text width with JavaScript

I'd like to use JavaScript to calculate the width of a string. Is this possible without having to use a monospace typeface? If it's not built-in, my only idea is to create a table of widths for each character, but this is pretty unreasonable…
Jacob
  • 10,452
  • 5
  • 22
  • 11
452
votes
15 answers

How to detect a textbox's content has changed

I want to detect whenever a textbox's content has changed. I can use the keyup method, but that will also detect keystrokes which do not generate letters, like the arrow keys. I thought of two methods of doing this using the keyup event: Check…
olamundo
  • 23,991
  • 34
  • 108
  • 149
416
votes
13 answers

How can I set focus on an element in an HTML form using JavaScript?

I have a web form with a text box in it. How do I go about setting focus to the text box by default? Something like this: so can anybody help me with it? I don't know how to set focus to the text box with…
tenstar
  • 9,816
  • 9
  • 24
  • 45
410
votes
33 answers

How do I get a TextBox to only accept numeric input in WPF?

I'm looking to accept digits and the decimal point, but no sign. I've looked at samples using the NumericUpDown control for Windows Forms, and this sample of a NumericUpDown custom control from Microsoft. But so far it seems like NumericUpDown…
Giffyguy
  • 20,378
  • 34
  • 97
  • 168
408
votes
5 answers

Multiline for WPF TextBox

I am developing an app for sending some feedback. Basically I'm trying to make a TextBox for comments, but I'm used to the WinForms MultiLine=true. I've set MinLines to 3, which is getting there, but preferably I'd like it if the user is able to…
baron
  • 11,011
  • 20
  • 54
  • 88
358
votes
13 answers

How do I automatically scroll to the bottom of a multiline text box?

I have a textbox with the .Multiline property set to true. At regular intervals, I am adding new lines of text to it. I would like the textbox to automatically scroll to the bottom-most entry (the newest one) whenever a new line is added. How do…
GWLlosa
  • 23,995
  • 17
  • 79
  • 116
320
votes
34 answers

Watermark / hint / placeholder text in TextBox?

How can I put some text into a TextBox which will be removed automatically when the user types something in it?
mehdi
262
votes
35 answers

How to automatically select all text on focus in WPF TextBox?

If I call SelectAll from a GotFocus event handler, it doesn't work with the mouse - the selection disappears as soon as mouse is released. EDIT: People are liking Donnelle's answer, I'll try to explain why I did not like it as much as the accepted…
Sergey Aldoukhov
  • 22,316
  • 18
  • 72
  • 99
260
votes
20 answers

Any way to make a WPF textblock selectable?

How to allow TextBlock's text to be selectable? I tried to get it to work by displaying the text using a read-only TextBox styled to look like a textblock but this will not work in my case because a TextBox does not have inlines. In other words, how…
Alan Le
  • 8,683
  • 7
  • 36
  • 31
234
votes
11 answers

Set keyboard caret position in html textbox

Does anybody know how to move the keyboard caret in a textbox to a particular position? For example, if a text-box (e.g. input element, not text-area) has 50 characters in it and I want to position the caret before character 20, how would I go about…
jonhobbs
  • 26,684
  • 35
  • 115
  • 170
204
votes
2 answers

Open file dialog and select a file using WPF controls and C#

I have a TextBox named textbox1 and a Button named button1. When I click on button1 I want to browse my files to search only for image files (type jpg, png, bmp...). And when I select an image file and click Ok in the file dialog I want the file…
NoobMaster69
  • 2,291
  • 3
  • 18
  • 24
179
votes
5 answers

What is the correct value for the disabled attribute?

What is the correct value for the disabled attribute for a textbox or textarea? I've seen the following used before:
tskuzzy
  • 35,812
  • 14
  • 73
  • 140
165
votes
12 answers

What is a reasonable length limit on person "Name" fields?

I have a simple webform that will allow unauthenticated users to input their information, including name. I gave the name field a limit of 50 characters to coincide with my database table where the field is varchar(50), but then I started to…
EndangeredMassa
  • 17,208
  • 8
  • 55
  • 79
163
votes
31 answers

Making a WinForms TextBox behave like your browser's address bar

When a C# WinForms textbox receives focus, I want it to behave like your browser's address bar. To see what I mean, click in your web browser's address bar. You'll notice the following behavior: Clicking in the textbox should select all the text…
Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
1
2 3
99 100