Click here to Skip to main content
15,883,731 members
Please Sign up or sign in to vote.
1.11/5 (2 votes)
When I press enter button submit button will be enable . Below code is working in IE but its not working in google chrome


JavaScript
<script type="text/javascript">
     
      
                function doClick(Button1, e) {
                                var key;

                    if (window.event)
                        key = window.event.keyCode;     
                    else
                        key = e.which;     

                    if (key == 13) {
                
                        var btn = document.getElementById(Button1);
                        if (btn != null) { 
                            btn.click();
                            event.keyCode = 0
                        }
                    }
        }

       


</script>
Posted
Updated 23-Jun-15 19:10pm
v2

You are doing it all wrong. First of all, keyboard event handlers are called with passing only one argument, not two. Therefore, your second actual argument is undefined. When you dereference this underfined object attempting to take e.which, an exception is thrown and probably not caught, and, anyway, the whole thing does not work.

Besides, window object does not have the property "event", with similar "results". An attempt to get window.event returns underfined, too.

You need to use a handler with only one argument, which is an event object. The actual object passed will be the KeyboardEvent object, which you can use to extract all the event properties you need. This is well explained here:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent[^],
http://javascript.info/tutorial/keyboard-events[^].

—SA
 
Share this answer
 
you did not select a on-click event in button... double click your button and write the code there...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900