Focusing and Selecting the Text in ASP.NET TextBox Controls
Posted
on 4 Guys From Rolla
See other posts from 4 Guys From Rolla
Published on Wed, 16 Feb 2011 00:00:00 GMT
Indexed on
2011/02/16
7:26 UTC
Read the original article
Hit count: 214
When a browser displays the HTML sent from a web server it parses the received markup into a Document Object Model, or DOM, which models the markup as a hierarchical structure.
Each element in the markup - the <form>
element, <div>
elements, <p>
elements, <input>
elements, and so on - are represented as a node in the DOM and can be programmatically accessed from client-side script. What's more, the nodes that make up the DOM
have functions that can be called to perform certain behaviors; what functions are available depend on what type of element the node represents.
One function common to most all node types is focus
, which gives keyboard focus to the corresponding element. The focus
function is commonly
used in data entry forms, search pages, and login screens to put the user's keyboard cursor in a particular textbox when the web page loads so that the user can start
typing in his search query or username without having to first click the textbox with his mouse. Another useful function is select
, which is available for
<input>
and <textarea>
elements and selects the contents of the textbox.
This article shows how to call an HTML element's focus
and select
functions. We'll look at calling these functions directly from client-side
script as well as how to call these functions from server-side code. Read on to learn more!
Read More >
© 4 Guys From Rolla or respective owner