Hello,
I have a function that lets me convert one character and throw an alert
with the corresponding ASCII value, but what I am having trouble with
is applying it to a text box. What I'm trying to do is when characters
are entered the function will loop through the entered values and throw
an alert for each of the corresponding ASCII values for each of the
characters entered. I am trying to alert the user for every character
that is out of the range of ASCII equivalent 1 - 128. Test code below.
Thanks in advance,
KP
function asciiValue(c)
{
// restrict input to a single character
c = c.charAt(0);
// loop through all possible ASCII values
var i;
for (i = 0; i < 256; ++ i)
{
// convert i into a 2-digit hex string
var h = i.toString (16);
if (h.length == 1)
h = "0" + h;
// insert a % character into the string
h = "%" + h;
// determine the character represented by the escape code
h = unescape(h);
// if the characters match, we've found the ASCII value
if (h == c)
break;
}
return i;
}
function update()
{
var inp = document.f.inp.value;
if (inp != "")
{
var result = asciiValue(inp);
document.f.outp.value = result != null ? result : "???";
document.f.inp.value = "";
}
else
alert ("You must enter a character first.");
document.f.inp.focus();
}