473,403 Members | 2,323 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,403 software developers and data experts.

Grabbing single ASCII values pasted into a text area

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 of text was pasted
in, and then grab the ascii value(s) that are > 128?:

<script type="text/javascript">
function toASCII(s)
{
var r = [];
for (var i=0, j=s.length; j--; i++){
r[i] = s.charCodeAt(i);
if (r > 128)
{
alert('"' + String.fromCharCode(r) + '"' + " Is not an acceptable
character.");
document.form1.textarea1.value="";
document.form1.textarea1.focus();
return false;
}
else
{
return true;
}
}
//return r.join(' ');
}
</script>

<BODY>
<form name="form1">
<textarea name="textarea1" onBlur="toASCII(this.value);"></textarea>

<!--<textarea name="textarea1"
onBlur="onBlur="document.getElementById('xx').inne rHTML =
toASCII(this.value);"></textarea>-->
<br>
<div>ASCII character codes
<!--<div id="xx"></div>-->
</div>
<input type=reset value="clear" onClick="document.form1.reset()">
</form>
</BODY>

Thanks in advance,
KP

Mar 10 '06 #1
1 4213
Kermit Piper wrote:
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 of text was pasted
in, and then grab the ascii value(s) that are > 128?:
There are no "ASCII values" beyond code point 127, ASCII is a 7-bit code.
And most certainly you mean > 127.
<script type="text/javascript">
function toASCII(s)
See above.
{
var r = [];
for (var i=0, j=s.length; j--; i++){
The value of `i' will be always what s.length-j evaluates to, so one of both
variables is redundant.
r[i] = s.charCodeAt(i);
OK, you are creating a new array element with the value of the code of the
character at position `i'.
if (r > 128)
But `r' refers to an Array object. It cannot work this way.
{
alert('"' + String.fromCharCode(r) + '"' + " Is not an acceptable
It would be more simple/easier/better if you just used s.charAt(i) here.
character.");
Use multiples of two spaces to indent your code, not the Horizontal Tab
character. Avoid code that exceeds the 80-columns margin, especially when
posting it; 72 or 76 are good numbers. IIRC there is a documentation
standard that even calls for word wrap after column #67.
document.form1.textarea1.value="";
document.form1.textarea1.focus();
See below.
return false;
}
else
{
return true;
}
}
//return r.join(' ');
}
</script>

<BODY>
<form name="form1">
The `action' attribute is missing.
<textarea name="textarea1" onBlur="toASCII(this.value);"></textarea>
Do not validate `onblur'. Use a button to validate instead. That can also
be a submit button in which case you would use the `onsubmit' handler of
the `form' element instead of the `onclick' handler of the button.

Pass `this' instead of `this.value', and you can use the `form' property
(or the passed reference itself, if called from an event handler for the
`form' element), coding standards compliant and avoiding any dependency
on the `form' element's name.

Search the archives for "form validation".
[...]
<input type=reset value="clear" onClick="document.form1.reset()">


The `onclick' code here is nonsense, since it is already a reset
button (input[type=reset]). Remove the entire attribute.
PointedEars
Mar 12 '06 #2

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

Similar topics

0
by: DenoxiS | last post by:
Hi, I've been working on a project that will help me save some time. It basically reads a URL and saves it to disk as an html file. In other words, I just wanted to make the automated version of...
2
by: Mervyn Carter | last post by:
Dear Friends IE5+, Win9*, not Netscape - I understand getSelection() is Netscape only. Anyone know of a way to access an area of mouse selected text within a <SPAN> or <DIV> ( ie not in a...
4
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
1
by: Kermit Piper | last post by:
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...
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....
6
by: davetelling | last post by:
I am a total newbie, trying to slog through the Visual C# Express application. I need to be able to convert a single ASCII character (can be anything from 0 to 255) to an int for use in other...
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. ...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.