Solved

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

Posted on 1999-01-15
8
3,459 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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
 
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

623 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