Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with ASCII code 1

Status
Not open for further replies.

daph

Programmer
Joined
Jun 9, 2000
Messages
65
Location
CA
Hi everyone!

I was just wondering how I can work with ASCII codes in javascript...for example..say I'd want to verify if my character value is a space (#32), how would I write it in javascript? It's more of a syntax question than anything else I guess.

Thanks a lot for your help! :)

daph
 
Hi daph,

use "e.which" for Netscape, and "event.keyCode" for IE
try this,

<script language=&quot;JavaScript&quot;>
var IE4 = (document.all);
var NS4 = (document.layers);
var NS6 = (document.getElementById && !document.all)

if (NS4 || NS6) document.captureEvents(Event.KEYPRESS);
document.onkeypress = ShortCut;

function ShortCut(e) {
whichASC = (NS4 || NS6) ? e.which : event.keyCode;
switch (whichASC) {
case 13: alert(&quot;Enter Key&quot;);break;
case 32: alert(&quot;Space key&quot;);break;
default:break;
}
}
</script>

hope this helps, Chiu Chan
WebMaster & Software Engineer
emagine solutions, inc
cchan@emagine-solutions.com
 
hey :)

what does event.keycode do? I mean, is event something that you can specify or is it predefined? I was asking because I had to look for this caracter at a certain position in an input field, not by the keyboard input.....
PS (I'm working with IE)

thanks again! :)

daph
 
you can check a chararacter code at a specific place in a string by using:

cha = sString.charCodeAt(nIndex)

It will return to you the ASCII code of the character in position nIndex (strings begin indexing, like arrays, at 0). jared@eae.net -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top