开发者

Autocomplete and User define keyboard

开发者 https://www.devze.com 2022-12-26 06:37 出处:网络
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

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) {
}


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号