3.0.4

Enter pressed in an input box

Hey there,

Is there a way to catch the keypressed event on an input control, so that you can later on submit a form...

Something like
input.keypressed = function(event)
{
if (event.keyCode =13) doSubmit();
else doNotSubmit();
}

thks
Peg
January 30,
Are you talking about an AW Input control or a basic HTML input element?
Jim Hunter
January 30,
Sorry, of course I am talking about AW Input control!!!

Know the answer?
Peg
January 31,
Try:

inputObj.getTemplate('box/text').setEvent("onkeypress", function(e){
  var keycode;
  if (window.event) keycode = window.event.keycode;
  else if (e) keycode = e.which;
  if (keycode=13) {
    // do your code here
  }
}


it's either getTempalte or getContent, I haven't done this yet or tested this code so sorry about that. You might even try it without the template part and just try inputObj.setEvent(...).

Good luck.
Jim Hunter
January 31,
Ok, here is what I got :

inputObj.getTemplate('box/text').setEvent("onkeypress", alert("toto"));

Produces an error.

inputObj.getContent('box/text').setEvent("onkeypress", alert("toto"));

alerts toto on body load only

inputObj.setEvent("onkeypress", alert("toto"));

alerts toto on body load only

So I'll keep trying... would be nice to have something like cellvalidation of the grid here.

Anyway, thanks for your help jim... You also a good guy, like alex!!!
Peg
January 31,
You have to wrap your code in the "function(){ your code }" methodology.IE:

inputObj.getTemplate('box/text').setEvent("onkeypress", function() {alert("toto")});


inputObj.getContent('box/text').setEvent("onkeypress", function(){ alert("toto")});


inputObj.setEvent("onkeypress", function(){ alert("toto")});


This is true with any Javascript event handler. I would expect your above examples to trigger on page load. My original example showed the use of "function(){ }", you must not remove it or it won't work...
Jim Hunter
January 31,
Ok, I should listen better when the teacher speaks...

So Both last options are ok now, but they only catch regular characters from keyboard, like letters, and so on...
Enter key might be grabbed somewhere else?
Peg
January 31,
it might be trapped at the page level. I remember when I was doing keyboard trapping for another project, I had to trap it at the page level. I only had one form on the page so it was easy to then issue the submit method of that form. I didn't need to try and figure out what control had focus at the time the ENTER key was pressed. Here is what I did for that project (I was just looking for the ESC key to be pressed and if so hide a popup calendar, and this was for an IE only application):

document.onkeypress = doKey;
function doKey(e) {
  if (event.keyCode==27)
    hideCalendar()
}
Jim Hunter
January 31,

This topic is archived.

See also:


Back to support forum