Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
keypress events, on an input field in a xhtml1 strict page. is IE able to do that ?
Old 06-21-2007, 11:37 AM keypress events, on an input field in a xhtml1 strict page. is IE able to do that ?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Hey folks,

For once, it's me that need a bit of enlightenment.

I want add an "keypress" event on a text input field in a Xhtml1 strict (and no, I don't want to downgrade it in "loose" doctype) page.
Xhtml specify that inline events are deprecated, so onkeypress="" is a no go.

My problem is that with ie, nothings happens...
Yes, I know that addEventHandler dont work with ie, and that the event name change.
I'm using prototype usually, but I also tried by hand, and with some obscure other js library to come to a solution, but without any success.

On Firefox, I can do what I want without any problems.
I put the keypress eventListener on the input, and the browser catch the keypress in this input.
I could not test it with safari (no mac, and safari for windows crash on submitting the request...), so if any of you can try it, it'll be greatly appreciated.

IE don't catch the event on the input element, only on the "document" element.
I didn't put the code here, as I use prototype, it will be irrelevant to simply show you the prototype instantiation.

That's a bit annoying, as it means that any keypress, even without having the focus on the input will trigger the function managing this input content.

Do any of you know how to make it work, of if even IE is capable to do that ?
I've tried googling a couple of hours, but without success.

Page here: http://seo.webalis.com

Thanks.
Tripy.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 06-21-2007 at 11:41 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
 
Register now for full access!
Old 06-21-2007, 08:47 PM Re: keypress events, on an input field in a xhtml1 strict page. is IE able to do that
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Can you place a condition in the js something like:

if (document.getElementById('inpTxtWord').focus == true) { . . .

or something like that??
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-22-2007, 04:38 AM Re: keypress events, on an input field in a xhtml1 strict page. is IE able to do that
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Tried it, but it returned false in Firefox....

I had:
Code:
function getResults(){
  if(to!=false){
    clearTimeout(to);
  }
  if(i$('inpTxtWord').focus == true){
      to=setTimeout('doGetResults()',500);
  }
}
I now have affined it by filtering the keystroke, to react only uppon characters, space, backspace and return.
Not perfect, but better:
Code:
function isAlpha(evt){
  evt = (evt) ? evt : (window.event) ? event : null;
  if (evt){
    var charCode = (evt.charCode) ? evt.charCode :
                   ((evt.keyCode) ? evt.keyCode :
                   ((evt.which) ? evt.which : 0));
    if( (charCode >= 65 && charCode <=90) 
        || 
        (charCode >= 97 && charCode <=122)
        ||
        (charCode == 8 || charCode ==13 || charCode==32)){
      return true;
    }
  }
  else{
      return false;
  }
}

function getResults(e){
  if(to!=false){
    clearTimeout(to);
  }
  if(isAlpha(e)){
      to=setTimeout('doGetResults()',500);
  }
}
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 06-22-2007 at 04:44 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to keypress events, on an input field in a xhtml1 strict page. is IE able to do that ?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.44029 seconds with 12 queries