JavaScript - onKeyPress, onKeyUp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DevInCode
    New Member
    • Apr 2008
    • 55

    JavaScript - onKeyPress, onKeyUp

    Hello
    I have an input box and a button that runs a function taking the input as a parameter. The button click works fine. The problem is it needs to respond to the enter key. I have it responding to the enter key, but in both ff and ie it loads the function produces the correct output, but then it looks like the page refreshes and the output is gone.

    Suggestions?

    Code:
    function test(e)
    {
    
    	var e = e.keyCode
    	if (e == 13)
    	{
    		findit();
    		alert("Hi!")
    	
    	} 
    }
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    default browser behavior is to submit a form if there is a single input text element and enter is pressed.

    set the form's onsubmit method to return false,
    and call its submit() directly when you want to upload the form.

    Comment

    Working...