Solved

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

Posted on 1999-01-15
8
3,447 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery scrollTop 2 40
validation, if text area is typed or pasted into 2 25
Don't understand jquery promises 6 36
Detect change of Select using JavaScript Only 12 45
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

929 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

10 Experts available now in Live!

Get 1:1 Help Now