Q:

Scanning data into mvc web application then changing focus

I am writing a small database where I can scan multiple bar codes into different text boxes then save the data. The bar code data can have some variance in length and I would like to move focus to the next text box after the bar code is done scanning. 
Here is the latest code in my view where I give each text box an id then I use jquery to focus on the next id after the first text box has reached a certain length.
<!--This is for entering the PartNumber-->
<div class="form-group">
    @Html.LabelFor(model => model.PartNum, 
       htmlAttributes: new { @class = "control-label col-md-2" })
    @Html.TextBoxFor(model => model.PartNum, 
       new { htmlAttributes = new { @class = "form-control", id="focus1"} })
    @Html.ValidationMessageFor(model => model.PartNum, "", 
       new { @class = "text-danger" })
</div>

        <!--This is for entering the Aisle-->
        <div class="form-group">
            @Html.LabelFor(model => model.Aisle, 
               htmlAttributes: new { @class = "control-label col-md-2" })
            @Html.TextBoxFor(model => model.Aisle, 
                new { htmlAttributes = new { @class = "form-control",id="focus2" } })
            @Html.ValidationMessageFor(model => model.Aisle, "", new { @class = "text-danger" })
        </div>

Here is my jquery code
$('input[id=focus').keyup(function () {
        if (this.value.length == 2) {
            $('input[id=focus2]').focus();
        }
    });

From what I can tell from the code, this should move focus to the next textbox after 2 characters are entered/scanned into the first textbox, but this does not work. 
I would then like to make the focus change after the barcode of variable length is done scanning but not sure how to do this.
What am I doing wrong in my code that will not let focus change to the next textbox?

A:

I discovered the main issue I was having was I forgot to include 
  $(function(){
at the start of my code.
On to the main solution that I was able to work out.
$(function(){
    $('#focus1').keyup(function(){
        if(!_timeoutRunning){
            _timeoutRunning=true;
            setTimeout(function(){checkKey();}, 2000);
        }
    });
});

var _timeoutRunning = false;

function checkKey(){
    _timeoutRunning = false;
    if($('#focus1').val().length >= 7)
        $('#focus2').focus();
}

this code allows me to scan in a bar code that is of length 7 or more then 2 seconds after the 7th character is scanned in it will change focus to the next id

