Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max length of text box moves cursor

Status
Not open for further replies.

ynnepztem

Programmer
Aug 2, 2001
54
US
I am using VB.Net, SQL Server 2000, Windows 2000. I have an application where a user needs to enter a number into three separate text boxes. The first one has a max length of 3, the second, 1 and the third 4. I don't want them to have to tab or click into the next box. How can I tell the cursor to setfocus into the next box when the maxlength has been reached. I could do this in VB6 very simply and I know how to send the cursor to another text box when coming from an error message or on form load. Any help would be greatly appreciated.
 
My guess would be you would have to set the Onchange event to call a javascript function that checks to see what position the user has input...then if it's last position

document.all('txtPhone2').focus();
 
Ok now I'm excited. My problem is I have no clue about Java Script. Can you give me a clue as to what to put exactly where?
 
textBox.Attributes.Add("onchange", "javascript:return moveCursor(this.form);")

okay, first you can add this attribute in the onload event of the page (code-behind) then you'll need to add this function within the HTML Script tags...

<script>
function moveCursor(form) {
...code to check where the length is...
if length equals form.elements["textBox"] then
document.all("textBox2").focus();
if length equals form.elements["textBox2"] then
document.all("textBox3").focus();
}

something like this...If I were you I'd post this javascript question in the javascript forum...if you find an answer, post it here as well...I am not sure how to check for length...the focus code will work...

dlc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top