Solved

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

Posted on 1999-01-15
8
3,449 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

803 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