Solved

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

Posted on 1999-01-15
8
3,446 Views
Last Modified: 2012-05-04
   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=?
0
Comment
Question by:idt
  • 4
  • 3
8 Comments
 
LVL 3

Author Comment

by:idt
ID: 1276972
Edited text of question
0
 
LVL 3

Author Comment

by:idt
ID: 1276973
Edited text of question
0
 
LVL 6

Accepted Solution

by:
PBall earned 30 total points
ID: 1276974
var X;
        var Foo;
        Foo=65;
        X=String.fromCharCode(Foo)

 
 
 
0
 
LVL 6

Expert Comment

by:PBall
ID: 1276975
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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Author Comment

by:idt
ID: 1276976
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"
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1276977
I heard that it was a "state math incompetency tax".
0
 
LVL 6

Expert Comment

by:PBall
ID: 1276978
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 :)
0
 
LVL 3

Author Comment

by:idt
ID: 1276979
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!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now