Link to home
Create AccountLog in
Avatar of hefterr
hefterrFlag for United States of America

asked on

The Enter Key?

Hi,
I am primarily a server side programmer (ColdFusion) and all of our application forms are button/link driven.

Q:  How does the browser decide what action to take when the "enter" key his hit in lieu of a submit button (or multiple buttons)?  Can this be controlled via Javascript or HTML?

Thanks in advance,
hefterr
ASKER CERTIFIED SOLUTION
Avatar of OriNetworks
OriNetworks

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
you can also control what the enter key does by adding a onkeypressdown event to your page and detecting if its an enter key and taking the appropriate action
i have written an ajax chat using php.

on the clientsided side i have running code such as this:

<textarea id="input" onkeydown="return check(this, event);"></textarea>
<input type="button" onclick="send(document.getElementById('input').value); document.getElementById('input').value = '';" value="send" />

Open in new window


the check function simply does this:
function check (that, e) {
	if (e.keyCode == 13) {
		if (e.shiftKey) {
			// insertatcursor (that, "\n");
			return true;
		} else if (trim(that.value) != "") {
			send(that.value);
			that.value = "";
			return false;
		}
		return false;
	}
}

Open in new window



hopefully this might help you.
Avatar of hefterr

ASKER

To all,
Thanks for your answers.  I found this post also.  Does it makes sense?
http://mentaljetsam.wordpress.com/2007/04/23/submit-a-html-form-with-the-enter-key/

I think the primary answer I was looking for was from "OriNetworks":
"pressing enter usually just submits the form via the action attribute of the form tag."