[CLOSED] How to call a javascript function when the ENTER key is pressed in a TextArea control?

  1. #1

    [CLOSED] How to call a javascript function when the ENTER key is pressed in a TextArea control?

    Hi,

    Could you tell me please How to call a javascript function when the ENTER key is pressend in a TextArea control?
    Last edited by Daniil; Aug 27, 2010 at 6:17 PM. Reason: [CLOSED]
  2. #2
    Hello!

    Please look at the example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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 runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var specialKeyHandler = function(field, e) {
                if (e.getKey() == e.ENTER) {
                    alert("Enter was pressed");
                }
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TextArea runat="server" EnableKeyEvents="true">
            <CustomConfig>
                <ext:ConfigItem Name="enterIsSpecial" Value="true" />
            </CustomConfig>
            <Listeners>
                <SpecialKey Fn="specialKeyHandler" />
            </Listeners>
        </ext:TextArea>
        </form>
    </body>
    </html>
  3. #3
    Hi,

    I need to call the same javascript function when a button is pressed. Is there a way to call the function when the key ENTER is pressed without having to send the special key as parameter?
  4. #4
    Hello!

    If I understood you properly this example will be useful for you. Just press Enter after page load.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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 runat="server">
        <title>Ext.Net Example</title>
        <script type="text/javascript">
            var specialKeyHandler = function(field, e) {
                if (e.getKey() == e.ENTER) {
                    alert("Enter was pressed!");
                }
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:KeyMap runat="server" Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}">
            <ext:KeyBinding>
                <Keys>
                    <ext:Key Code="ENTER" />
                </Keys>
                <Listeners>
                    <Event Fn="specialKeyHandler" />
                </Listeners>
            </ext:KeyBinding>
        </ext:KeyMap>
        <ext:Button ID="Button1" runat="server" Text="Button">
            <Listeners>
                <Click Handler="alert('Hello from click listener!')" />
                <AfterRender Handler="this.focus()"/>
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>

Similar Threads

  1. Call JavaScript function with CellSelection
    By bolzi89 in forum 1.x Help
    Replies: 5
    Last Post: Dec 23, 2011, 2:42 PM
  2. Replies: 8
    Last Post: Dec 23, 2011, 12:41 PM
  3. How to call the javascript function form code behind
    By harshad.jadhav in forum 1.x Help
    Replies: 3
    Last Post: Mar 29, 2011, 3:00 PM
  4. [CLOSED] Call Javascript Function
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 21, 2010, 3:58 AM
  5. [CLOSED] How to call a javascript function from a child page?
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 25, 2010, 5:40 PM

Posting Permissions