asp.net mvc 4 - How to Auto Tab(Cursor) in Html.TextBoxFor(or Html.TextBox)? -
i'm new in asp.net mvc 4, , have questions
i have 5 textbox following picture(link).
http://i.stack.imgur.com/hmjjp.png
in each textbox set maxlength its. following picture(link)
http://i.stack.imgur.com/rsi4u.png
example : textbox1 -> maxlength = 1 textbox2 -> maxlength = 4 textbox3 -> maxlength = 5
i want auto tab when insert data each textbox.
example : when insert "1" textbox1(maxlength=1) cursor go textbox2 auto
and thereafter want set data textbox
example : string value = textbox1 + textbox2 + ... + textbox5
value = 1222233333...
please accept sincere apology in advance mistake may occur.
thank much.
something following should work,
markup
<div class="tax"> <input type="text" maxlength="1" /> <input type="text" maxlength="4" /> <input type="text" maxlength="5" /> <input type="text" maxlength="2" /> <input type="text" maxlength="1" /> </div>
script
$(function () { $('.tax input[type="text"]').keypress(function (e) { if (e.which == 0 || e.charcode == 0) { return true; } var str = string.fromcharcode(!e.charcode ? e.which : e.charcode); str = $(this).val() + str; if (str.length == $(this).prop('maxlength')) { var = this; window.settimeout(function(){ $(that).next('input[type="text"]').focus(); }, 0); } }); });
fiddle: http://jsfiddle.net/tkasd/5/
hope helps.
Comments
Post a Comment