Link to home
Start Free TrialLog in
Avatar of idt
idt

asked on

The JavaScript equiv of chr(65)..'A'

   I have a var foo=65 I want to put 'A' into another var

    in vb, is simple:
       Dim X as String * 1
       Dim Foo as Integer
       X=chr(Foo)

    in c, is simple:
        char X;
        int Foo=65;
        X=(char)foo;

    in javascript:
        var X;
        var Foo;
        Foo=65;
        X=?
Avatar of idt
idt

ASKER

Edited text of question
Avatar of idt

ASKER

Edited text of question
ASKER CERTIFIED SOLUTION
Avatar of PBall
PBall

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
Unfortunately, this will only work on 4.0+ browsers (tested on IE)

Perhaps other experts might have some other solution..hmm.  I couldn't find any.
Avatar of idt

ASKER

Geeez.. PBall my man!  helluva lot easy than what I just set out to do.. :)

var alphabet=" !'#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~";

if((iKey<32)||(iKey>127)) return;
X=alphabet.charAt(iKey-32));
on older browsers I just may use this, or not support them.

I tried to use that earlier, though it was used somestring.fromCharCode(n).

Tested your's, works great on NS and IE, except (and now this is optional) :
    event.keyCode on IE always returns the UpperCase value.. 65 for 'a' 65 for 'A'
    I'd like to know the case if possible.

If you don't know, or care to answer within this thread, comment back and I'll accept your answer as is

Thanks

-iDT
"lotteries are a tax on people bad in statistics"
I heard that it was a "state math incompetency tax".
Yes it does, depending on what event you are detecting it, the keyCode will return different things.

for example:

onKeyPress will return both (A = 65, a = 97)

but when you trap onKeyUp or onKeyDown it will just return the scancode (A = 65, a = 65)

give that a try.

Heh, actually that's not bad at all (the way you are trying to detect it).  You can somewhat use that solution to build your own chr function for non 4.0 browsers :)
Avatar of idt

ASKER

Unfortunately, I need to use the onKeydown, as I need to trap on that elusive chr(13)!.. and onKeypress in a text box.. nada.

The alphabet function above demonstrates further the frustration of IE and NS, NS sends lowercase on keydown, IE does not, NS skips a few key codes though.. the \ and one other, IE doesn't skip, so you would need to have an alphahabet defined unique to each browser.

bleagh :(

-iDT
further oddity:
<input name="Foo" value="" Size="18" onKeydown="return handleKey(event)">
in NS if handlekey returns false, the keystroke is cancelled, in IE, it lives!