Link to home
Start Free TrialLog in
Avatar of robertybob
robertybob

asked on

OnKeyPress workaround for IE Mobile

I am coding a very simple page that uses onkeypress to alter a formfield and then submit the form on the page. I would like to be able to use this page from my mobile device but I found info that tells me that IE Mobile doesnt support any Event captures.

Is there a workaround for this that utilises IE Mobile capabilities to the same end result?

Thx
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

onkeypress of what?
how do you capture?

Do you have
<input type="text" onKeyPress="something(this)">

or is it
document.onkeypress=something;
Avatar of robertybob
robertybob

ASKER

hi mplungjan - the code uses something like this to insert a word into the formfield. Works in normal IE, doesnt seem to work in FF but no probs at the moment.....main thing is to get it to work on IE Mobile

function keyHandler(e){
    var pressedKey;
    var selection;
    if (document.all)    { e = window.event; }
    if (document.layers) { pressedKey = e.which; }
    if (document.all)    { pressedKey = e.keyCode; }
    pressedCharacter = String.fromCharCode(pressedKey);
    if(pressedKey=='97') { selection = 'Apple'; }
    if(pressedKey=='98') { selection = 'Banana'; }
    if(pressedKey=='99') { selection = 'Cherry'; }
    document.boxform.word.value = selection;
}
document.onkeypress = keyHandler;

hope this helps :)
For FF/NS/Mozilla and IE:


function keyHandler(e){
    var pressedKey = (e) ? e.which : window.event.keyCode;
    var pressedCharacter = String.fromCharCode(pressedKey);
    if(pressedKey=='97') { selection = 'Apple'; }
    if(pressedKey=='98') { selection = 'Banana'; }
    if(pressedKey=='99') { selection = 'Cherry'; }
    document.boxform.word.value = selection;
}
document.onkeypress = keyHandler;

Can you perhaps do

var fruit = { a: "Apple", b: "Banana", c: "Cherry"}

<input type="text" onKeyUp="if (fruit[this.value]) this.value=fruit[this.value]">

the onKeyUp version doesnt trigger either :(

dont think IE Mobile allows any onkeydown, onkeyup, onkeypress, onmousemove, onmousedown and onmouseup events - not sure if there's a coding way round this or if MS have some kind of add-on package to boost the mobile IE functionality
Of course I'm only suggesting IE Mobile cos its on the device - if anyone can categorically confirm that these events are handled by another mobile browser which can also handle things like Ajax and all other IE capabilities then thats fine - I can try that if its free of charge.

Thx

I am frankly very surprised... I have a Nokia n80 and its browser can handle almost all javascript...
Yup me too :) I have word that IE5 couldnt support this but IE6 can so i'm trying to investigate the software on the clients device tmrw. Tho its brand new and the spec says IE6 Mobile - will check with my own eyes on Monday and post here the conclusions.
ok - it seems to be version 6.12 but definitely not allowing onkeypress :(
Super strange...

If you wish, ask for a PAQ and refund
lol :) i've just noticed that the OS is WInCE not Win Mobile so just investigating if this makes any difference
ASKER CERTIFIED SOLUTION
Avatar of robertybob
robertybob

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Robertybob, you still around? This is still a problem with Windows Mobile, but there is a dirty workaround, if you're still interested. Post another question (and give me a heads up). :)