Invoking keypress event after entering 9 digits

Page 1 of 2 12 LastLast
  1. #1

    Invoking keypress event after entering 9 digits

    Hi,

    I would like to call a keypress event automatically after entering 9 digits number and keep the focus in the textbox control.
    Is this possible?

    Thanks,
    Kamal
  2. #2

    RE: Invoking keypress event after entering 9 digits

    Attach a listener to the keypress event (make sure enablekeyevents = true) and check the length of the textfield value. If 9, run your custom logic.
  3. #3

    RE: Invoking keypress event after entering 9 digits

    Thanks for your prompt reply. I will test it and let you know if I am successful!
  4. #4

    RE: Invoking keypress event after entering 9 digits

    Hi,

    Could you tell me how? I am not an expert on Javascript :-(! sorry. and how can I call an event from a keymap?

    Thanks,
    Kamal
  5. #5

    RE: Invoking keypress event after entering 9 digits

    Hi Kamal,

    Here's a sample.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Coolite Toolkit Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager runat="server" />
            
            <script type="text/javascript">
                var doSomething = function (el) {
                    var value = el.getValue();
                    
                    if (value.length > 8) { 
                        console.log("doSomething", value);
                    }
                };
            </script>
            
            <ext:TextField runat="server" EnableKeyEvents="true">
                <Listeners>
                    <KeyPress Fn="doSomething" />
                </Listeners>
            </ext:TextField>
        </form>
    </body>
    </html>
    Hope this helps.

    Geoffrey McGill
    Founder
  6. #6

    RE: Invoking keypress event after entering 9 digits

    Thanks Geoffrey. Does it keep the focus in the text box? Is there any other way to do it from code behind?

    Many thanks for your help.
    Kamal
  7. #7

    RE: Invoking keypress event after entering 9 digits

    Does it keep the focus in the text box?
    When you tested the code does the focus leave the TextField?


    Is there any other way to do it from code behind?

    Yes, you should be able to set the .Fn property of the Listener, although manually adding the 'doSomething' function into your page or .js file would be recommended.


    Hope this helps.


    Geoffrey McGill
    Founder
  8. #8

    RE: Invoking keypress event after entering 9 digits

    Thanks.

    
    
    When you tested the code does the focus leave the TextField?
    yes it does!
  9. #9

    RE: Invoking keypress event after entering 9 digits

    Hi Kamal,

    I just re-tested the sample above in IE, Firefox and Chrome and the focus never leaves the TextField.


    Geoffrey McGill
    Founder
  10. #10

    RE: Invoking keypress event after entering 9 digits

    Here's a modified sample which does not use console.log.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Coolite Toolkit Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <script type="text/javascript">
                var doSomething = function (el) {
                    var value = el.getValue();
                    
                    if (value.length > 8) { 
                        Label1.setText(value);
                    }
                };
            </script>
            
            <ext:TextField ID="TextField1" runat="server" EnableKeyEvents="true">
                <Listeners>
                    <KeyPress Fn="doSomething" />
                </Listeners>
            </ext:TextField>
            
            <ext:Label ID="Label1" runat="server" />
        </form>
    </body>
    </html>
    Geoffrey McGill
    Founder
Page 1 of 2 12 LastLast

Similar Threads

  1. TriggerField KeyPress event
    By reyonlines in forum 1.x Help
    Replies: 8
    Last Post: Oct 08, 2013, 6:29 AM
  2. [CLOSED] EditGridPanel and entering html markup as a value
    By bogc in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 27, 2012, 9:11 AM
  3. [CLOSED] KeyDown and KeyPress Event
    By rosua in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 04, 2012, 11:43 AM
  4. [CLOSED] keypress event
    By RomualdAwessou in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 18, 2011, 3:53 PM
  5. Replies: 1
    Last Post: Jun 12, 2009, 5:14 AM

Posting Permissions