JavaScript to automatically tab to next textbox

  Рет қаралды 38,508

kudvenkat

kudvenkat

Күн бұрын

Link for all dot net and sql server video tutorial playlists
/ kudvenkat
Link for slides, code samples and text version of the video
csharp-video-tu...
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our KZbin channel. Hope you can help.
/ @aarvikitchen5572
In this video we will discuss, how to automatically move the cursor keyboard focus from one textbox to another using JavaScript. Let us understand this with an example.
Consider a web page where we need to enter 16 digit bank card number. On this page we have 4 textboxes. Each textbox should allow only 4 numbers. Upon entering the first 4 card numbers in the first textbox, the cursor should automatically move to the second textbox. Upon entering the next 4 card numbers in the second textbox, the cursor should automatically move to the third textbox.
Here is the HTML and JavaScript function that automatically sets the focus to the next textbox
Card Number :
[asp:TextBox ID="txt1" runat="server" Width="50px" MaxLength="4"
onkeyup="moveCursor(this, 'txt2')" /]
[asp:TextBox ID="txt2" runat="server" Width="50px" MaxLength="4"
onkeyup="moveCursor(this, 'txt3')" /]
[asp:TextBox ID="txt3" runat="server" Width="50px" MaxLength="4"
onkeyup="moveCursor(this, 'txt4')" /]
[asp:TextBox ID="txt4" runat="server" Width="50px" MaxLength="4" /]
[script type="text/javascript"]
function moveCursor(fromTextBox, toTextBox)
{
// Get the count of characters in fromTextBox
var length = fromTextBox.value.length;
// Get the value of maxLength attribute from the fromTextBox
var maxLength = fromTextBox.getAttribute("maxLength");
if (length == maxLength)
{
// If the number of charactes typed in the fromText is
// equal to the maxLength attribute then set focus on
// the next textbox
document.getElementById(toTextBox).focus();
}
}
[/script]

Пікірлер: 13
@SushankB
@SushankB Жыл бұрын
thanks a lot for the video it helped me a lot
@pablovarela-germa259
@pablovarela-germa259 5 жыл бұрын
Thank you. Very clear. Cheers from Argentina.
@geld5220
@geld5220 6 жыл бұрын
what if i want to delete the input hitting back space, how would i go back to the previous input field without manually clicking on previous input?
@pctutorialhelp
@pctutorialhelp 7 жыл бұрын
Can we move cursor from fast tab to 6th tab with only one press in Tab Button? Please suggest me.
@abhinavkumar8271
@abhinavkumar8271 8 жыл бұрын
Very good..
@mahipalkamanchi
@mahipalkamanchi 9 жыл бұрын
thank u sir...!
@jaysingrajput6835
@jaysingrajput6835 5 жыл бұрын
Sir I want First two text box and then table in teble dynamically insert multi data
@volodymyrkozliuk6811
@volodymyrkozliuk6811 4 жыл бұрын
it was helpful
@orcunozdil8227
@orcunozdil8227 9 жыл бұрын
thanks a lot..
@JediPhantom
@JediPhantom 9 жыл бұрын
great stuff!..
@yasirujayashan
@yasirujayashan 4 жыл бұрын
ambooo oya nam deiyek nevi devalayak :)
@therock-m3k
@therock-m3k 6 жыл бұрын
Tks
@aleksejsaleksejevs7818
@aleksejsaleksejevs7818 6 жыл бұрын
(Y)
RegisterStartupScript and RegisterClientScriptBlock methods
16:11
JavaScript Pro Tips - Code This, NOT That
12:37
Fireship
Рет қаралды 2,5 МЛН
МЕБЕЛЬ ВЫДАСТ СОТРУДНИКАМ ПОЛИЦИИ ТАБЕЛЬНУЮ МЕБЕЛЬ
00:20
Touching Act of Kindness Brings Hope to the Homeless #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 19 МЛН
АЗАРТНИК 4 |СЕЗОН 3 Серия
30:50
Inter Production
Рет қаралды 952 М.
ASP NET TextBox and JavaScript
9:16
kudvenkat
Рет қаралды 47 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,2 МЛН
Controlling focus with tabindex -- A11ycasts #04
5:14
Chrome for Developers
Рет қаралды 229 М.
Frontend Web Development Projects that got me hired
10:38
James Cross
Рет қаралды 282 М.
ASP NET control client id in JavaScript
12:13
kudvenkat
Рет қаралды 22 М.
JavaScript to select all checkboxes in GridView
25:29
kudvenkat
Рет қаралды 39 М.
Adding JavaScript to ASP NET controls
13:12
kudvenkat
Рет қаралды 135 М.