javascript enter event not working properly in sharepoint..

javascript enter event not working properly in sharepoint..

Hi all,

I have implemented autosuggestion slide down  on the search box in sharepoint 2010 using a jquery plugin. On giving something in the search box it will give some suggestion and the traversing through the suggestion in the autosuggestion box can be done through key up and key down from the keyboard.It is working fine but when selecting on one of the suggestion and pressing on enter key the suggestion text should move to the search box(as in google),but this is not happening...sometym it is working and some it is not....What can be the problem?How it can be made consistent?

the code for enter event i am using inside a switch case like the below code snippet
 

$(document).ready(function () {
        $('#SearchTextBox').keyup(function (event) {
            var previousSelected = SelectedDivisionIndex;

            // catch some keys
            try {
                switch (event.keyCode) {
                    case 13:    // enter


var selectedDivision = $("#autosuggestionBox>div:eq(" + SelectedDivisionIndex + ") a");
                    if (selectedDivision .length == 1)
                    $('#SearchTextBox').val(selectedDivision.attr("name"));

here the "a" is a anchor tag :

 <a name='" + title + "'>" + $("Title", $(this)).text() + "</a>

that is written in some other js function in the same script.

What is wrong here?How it can be resolved?

Please suggest....

Thanks

Sucharita30