473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Grabbing ASCII values in a text box

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();
}

Mar 10 '06 #1
1 2975
Zif
Kermit Piper wrote:
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
'text box'? Do you mean a textarea or text input? Not that it really
matters I guess.

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.


If your range is 128 (which is the valid range for ASCII) why do you
loop to 256? Anyway, see if you can adapt this to suit (wrapped for
posting):

<script type="text/javascript">

function toASCII(s)
{
var r = [];
for (var i=0, j=s.length; j--; i++){
r[i] = s.charCodeAt(i);
}
return r.join(' ');
}

</script>

<textarea
onkeyup="document.getElementById('xx').innerHTML =
toASCII(this.value);"></textarea>
<div>ASCII character codes
<div id="xx"></div>
</div>
It only considers the actual characters entered into the text area.

[...]


--
Zif
Mar 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kermit Piper | last post by:
Hello, OK, almost there. Here's what I have so far, which handles characters as they're typed in. Could someone please show me how I would loop through all the values that are entered if a block...
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
2
by: joakim.hove | last post by:
Hello, I am having great problems writing norwegian characters æøå to file from a python application. My (simplified) scenario is as follows: 1. I have a web form where the user can enter his...
4
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.