views:

43

answers:

2

Hi All,

I am using asp:button to create a keyboard with A-Z and 0-9 for touch screen using Java script. This keyboard is linked with one textbox. If we click one button corresponding text will be displayed on the textbox. Its working fine. I have included the autocomplete feature to this textbox using jquery JQuery Autocomplete.

Problem:

  1. The autocomplete is not working if i my user define keyboard. How to modify my key buttons as keyboard keys[Set event keycode]? Is it possible? Is there any other way to achieve this?

Code:

 <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>

 <asp:Button ID="zero" runat="server" Text="0" CssClass="myclass" OnClientClick="return typeLetter(this);" TabIndex="20"/>

 function typeLetter(currentbutton) {
         if (previousActiveElement != null) {
             if (previousActiveElement == 'antSearchText'){

                 var position = document.getElementById('position').value;

                 if (position == '') {
                     alert('chk position');
                 } else {
                     var existingString = document.getElementById(previousActiveElement).value;
                     var beforeString = existingString.substring(0, position);
                     var afterString = existingString.substring(position, existingString.length);
                     document.getElementById(previousActiveElement).value = beforeString + currentbutton.value + afterString;
                                                                     setCaretPosition(document.getElementById(previousActiveElement), parseInt(position) + 1);
                     setCaretPosition(document.getElementById(previousActiveElement), parseInt(position) + 1);                         
                 }                     
             }                 
         }             
         return false;
     }

Edit:

In autocomplete plugin the following is getting the key event, How to pass same key event by using my keys?

  $input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
}
A: 

Try triggering the jQuery keydown/keyup event manually. I cannot recall for the life of me which one autocomplete triggers on, but here's the gist:

// your documment.getElementById(...)
jQuery('#'+previousActiveElement).keyup();
// your setCaretPosition

Try the different key events and one should cause the autocomplete to kick in.

Hope that helps!

Thanks, Joe

Joseph Mastey
A: 

Hi,

Problem get solved by using the following code.

Code:

var q = document.getElementById('txtbox');
var evObj = document.createEventObject();
evObj.keyCode = 84; // [T] key
q.fireEvent('onkeydown', evObj);

Geetha.

Geetha