Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
400
How to create a default button
posted

We have a couple of WebDialogWindows, they all have some input fieldS and  OK and Cancel buttons. The dialog is shown via client script and the OK/Cancel buttons are also handled by client script.

Now I want the OK button to behave as a default button, e.g. a user presses the enter key in any of the fields it must perform the OK action. How can I do this ?

Lex 

Parents
  • 995
    Verified Answer
    posted

    You can use following code:

    <input type="text" id="txtSearch" onkeypress="enterKeyPress(event);" />  

    <input type="text" id="txtSearchOne" onkeypress="enterKeyPress(event);" />  

    <script type="text/javascript" id="igClientScript">

    <!--

     

    function WebImageButton2_Click(oButton, oEvent){

        alert("OK buttun clicked...");

    }

     

    // -->

     

    function enterKeyPress(e)

            {

                    // look for window.event in case event isn't passed in

                    if (window.event) { e = window.event; }

                    if (e.keyCode == 13)

                    {

                        document.getElementById('<%= WebImageButton2.ClientID %>').click();

                    }

            }

    // -->

    </script>

Reply Children