We help IT Professionals succeed at work.

I have an event onmouseout and it is working well.  How do I also add onEnter pressed, to the event?

goodk
goodk asked
on
<input type="text" onmouseout="runthis(this)" OnEnter="tunthis(this">


??
Comment
Watch Question

Most Valuable Expert 2013
Awarded 2012
Commented:
Hi,

What event do you want to capture exactly? When the user presses the keyboard - enter key?
Then you have to use the "onkeypress" but also check the key code like
var key;

         if(window.event)
              key = window.event.keyCode;     // IE behaviour
         else
              key = e.which;     //Handling for FireFox
    
        if (key == 13)
        {

Open in new window

HTH
Rainer

Author

Commented:
when the user is done typing on the text field and either takes the mouse away or presses the enter key and at that time I want to fire either event.

Please tell me clearly- thanks
Most Valuable Expert 2013
Awarded 2012
Commented:
Hi,
then your code should look like this:
<script type="text/javascript">
function checkKeyCode(element) {
  var key;
  if(window.event)
    key = window.event.keyCode;     // IE behaviour
  else
    key = e.which;     //Handling for FireFox
    
  if (key == 13) {
    runthis(element);
  }
}
function runthis(element) {
// ... your original function
}
</script>
...
<input type="text" onmouseout="runthis(this)" onkeypress="checkKeyCode(this);">

Open in new window


HTH
Rainer

Author

Commented:
confuse? how would I add this checkKeyCode(this)  to the attached code?

Author

Commented:
Well, the same problem persist that the entire form gets submitted when I hit the enter key

Author

Commented:
Thank you