Jquery Auto Tab for Phone fields

Its a good thing, If  we implement autotab for telephone fields. It would be more nice. There are many Jquery plugins. But here I created my own simple autotab with a jquery function.

Here I'm explaining with rails application

Add onKeyup javascript event autotab() to your text fields in which you want to implement autotab

Then View should look like the following

<%=text_field_tag :isd, nil, :maxlength => 3, :onKeyup => "autotab(this)" %>
<%=text_field_tag :std, nil, :maxlength => 5, :onKeyup =>"autotab(this)"%>
<%=text_field_tag :num, nil, :maxlength => 12 %>

Then add the js function to your application.js

function autotab( field ){
if(field.getAttribute&&field.value.length==field.getAttribute("maxlength")){
    $(field).next('input').focus();
  }
}

This will do the autotab thing.
For any query please comment on the same thread. Thank you.

Comments

Popular posts from this blog

Rails Kaminari - Ajax pagination

Rails mongoid has field model validation

Rails Upgrading a project