Closed Thread Icon

Topic awaiting preservation: buttons (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=7939" title="Pages that link to Topic awaiting preservation: buttons (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: buttons <span class="small">(Page 1 of 1)</span>\

 
Ensabanur
Bipolar (III) Inmate

From: KY
Insane since: Nov 2001

posted posted 11-21-2001 06:10

Hey there, is it possible to program in javascript so when someone hits enter after typing in something the nearest button, or s designated button's action is started, such as when someone fills out a form and hitting enter would submit it.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 11-21-2001 08:39
code:
<form>
type here (press enter to submit):<input type="text" value="" onkeypress="chr = event.which ? event.which : event.keyCode; if (chr==13) this.form.submit();">
</form>





Ensabanur
Bipolar (III) Inmate

From: KY
Insane since: Nov 2001

posted posted 11-21-2001 16:26

should the "event.which" be replaced with something specific for my code?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-21-2001 18:59

No.

Lallous used some shorthand here to make the code cross-platform.

Js has on some platforms an "event" object. Which on some platforms has a "which" property. He's essetially saying with this line

chr = event.which ? event.which : event.keyCode;

if event.which is supported then assign whatever event.which is to the variable "chr" if it is not supported then make "chr" equal to whatever event.keyCode is.



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

[This message has been edited by bitdamaged (edited 11-21-2001).]

« BackwardsOnwards »

Show Forum Drop Down Menu