Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] [Javascript] enabling/disabling buttons: enter key



TLUG, Stephen,

After a little digging I now realize that the problem isn't the button,
it's the text field.

Apparently, unless you specify to disable the enter key in a text field,
then it's possible to trigger to send the form data with the enter key.

So it wasn't that the button was being triggered, it was that the form
data was being sent, and that made it look to me like the button was
being pressed.

I think what I want to do, then, is globally deactivate enter keys on
text boxes, because I always want to do specific Javascript when the
appropriate buttons are pressed.

I think this code I found on the web* might do it:

function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ?
evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}

document.onkeypress = stopRKey;

Will have to experiment.

* http://www.webcheatsheet.com/javascript/disable_enter_key.php

-- 
Dave M G


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links