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

unicode/ascii codes in javascript


Folks,

I have two related questions:

1. I have seen unicode being mentioned in my javascript pocket book - is
this the same as ascii codes? I think not though I'm not sure and I
can't find any examples...

2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...

Why? I am working on an application which allows the user to enter in
multiple names - I want to store these multiple names in a hidden text
box using a none-printable character as a field seperate for each input
text field value. I know 100% that my keyboard entries will be
ascii/qwerty.

Can someone steer me in the right direction?

randelld
Jul 23 '05 #1
13 8997
> 1. I have seen unicode being mentioned in my javascript pocket book - is
this the same as ascii codes? I think not though I'm not sure and I
can't find any examples...
ASCII is a subset of Unicode. Buy a better book.
2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...

Why? I am working on an application which allows the user to enter in
multiple names - I want to store these multiple names in a hidden text
box using a none-printable character as a field seperate for each input
text field value. I know 100% that my keyboard entries will be
ascii/qwerty.

Can someone steer me in the right direction?


Yeah. Don't do it. No security is obtained from such ridiculous methods.
The list of names must be kept on the server, never in the client.

http://www.crockford.com/javascript/survey.html
Jul 23 '05 #2
Douglas Crockford wrote:
1. I have seen unicode being mentioned in my javascript pocket book -
is this the same as ascii codes? I think not though I'm not sure and I
can't find any examples...

ASCII is a subset of Unicode. Buy a better book.
2. How do I read/set a string to an unprintable code? For example,
how can I set the variable a to equal the equivalent of ascii code 7
or 8 or whatever...

Why? I am working on an application which allows the user to enter in
multiple names - I want to store these multiple names in a hidden text
box using a none-printable character as a field seperate for each
input text field value. I know 100% that my keyboard entries will be
ascii/qwerty.

Can someone steer me in the right direction?

Yeah. Don't do it. No security is obtained from such ridiculous methods.
The list of names must be kept on the server, never in the client.

http://www.crockford.com/javascript/survey.html

Thanks - I am aware of security concerns - but security is not a problem
for me as I'm working on a small intranet based application - in
addition, I will sanitize my input using PHP...

Thus - canyou answer my second question? How can I sest a variable to be
the equivalent of ascii code 7 or 8 or whatever - I believe I can read a
string, and find the unicode values of each character, but I don't know
what function I can use for the reverse of this process.

cheers
randelld
Jul 23 '05 #3
Douglas Crockford wrote:
1. I have seen unicode being mentioned in my javascript pocket book -
is this the same as ascii codes? I think not though I'm not sure and I
can't find any examples...

ASCII is a subset of Unicode. Buy a better book.
2. How do I read/set a string to an unprintable code? For example,
how can I set the variable a to equal the equivalent of ascii code 7
or 8 or whatever...

Why? I am working on an application which allows the user to enter in
multiple names - I want to store these multiple names in a hidden text
box using a none-printable character as a field seperate for each
input text field value. I know 100% that my keyboard entries will be
ascii/qwerty.

Can someone steer me in the right direction?

Yeah. Don't do it. No security is obtained from such ridiculous methods.
The list of names must be kept on the server, never in the client.

http://www.crockford.com/javascript/survey.html


Ah! I've just realised that you have have also mis-understood my second
question... I do not want to have the names written as part of the
javascript... this I would agree, would be silly...

I have a form - it has INPUT tags asking for firstname and lastname.

I also have a hidden input box.

When the user enters a firstname and lastname, I have an onClick
function which takes the input from the firstname/lastname box, and
writes it to the hidden input box. I want this so as the client can
enter several names all at once without having to post the form each
time. Once they have finished inputing the names, the user clicks on a
submit button which then passes the hidden input box to my php based server.

In order for my php script to read the input, I want the hidden text box
to have a fixed format - thus, for example, firstname is always followed
by ascii character 8 followed by lastname. I can then easily unpack
this long string on the server side.

Thus - can you tell me how I can set a variable called fs equal to ascii
character 8? Or even unicode character 8? (It doesn't have to be 8 - but
something not readily available from qwerty keyboard input)

Thanks
Randell D.
Jul 23 '05 #4
Randell D. wrote:

<--snip-->
Thus - can you tell me how I can set a variable called fs equal to ascii
character 8? Or even unicode character 8? (It doesn't have to be 8 - but
something not readily available from qwerty keyboard input)


var fs="";

Copy and paste as desired. Unless someone you know spells a name with a
B like that. Then, you could use :

var fs="";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
Randy Webb wrote:
Randell D. wrote:

<--snip-->
Thus - can you tell me how I can set a variable called fs equal to
ascii character 8? Or even unicode character 8? (It doesn't have to be
8 - but something not readily available from qwerty keyboard input)

var fs="";

Copy and paste as desired. Unless someone you know spells a name with a
B like that. Then, you could use :

var fs="";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.


Yep - I agree that it only has to be unique and I'm grateful for your
suggested solution (which I will use) however I guess there is no method
available in javascript to do what I want to do... true? (Just for a
curiosity/js-educational point of view).

thanks
randelld
Jul 23 '05 #6
Randell D. wrote:
Randy Webb wrote:
Randell D. wrote:

<--snip-->
Thus - can you tell me how I can set a variable called fs equal to
ascii character 8? Or even unicode character 8? (It doesn't have to
be 8 - but something not readily available from qwerty keyboard input)


var fs="";

Copy and paste as desired. Unless someone you know spells a name with
a B like that. Then, you could use :

var fs="";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.


Yep - I agree that it only has to be unique and I'm grateful for your
suggested solution (which I will use) however I guess there is no method
available in javascript to do what I want to do... true? (Just for a
curiosity/js-educational point of view).


Never really tried but instincts tells me it should be able to, provided
you can get the Unicode character sequence for it.

A while back I wrote a script that I needed a delimiter for much as you
need one and settled on the following:

var myVar = "ޱ";

And unless someone every happened to type that particular sequence then
my app is pretty secure :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7
Randy Webb wrote:
Randell D. wrote:
Randy Webb wrote:
Randell D. wrote:

<--snip-->

Thus - can you tell me how I can set a variable called fs equal to
ascii character 8? Or even unicode character 8? (It doesn't have to
be 8 - but something not readily available from qwerty keyboard input)


var fs="";

Copy and paste as desired. Unless someone you know spells a name with
a B like that. Then, you could use :

var fs="";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.


Yep - I agree that it only has to be unique and I'm grateful for your
suggested solution (which I will use) however I guess there is no
method available in javascript to do what I want to do... true? (Just
for a curiosity/js-educational point of view).

Never really tried but instincts tells me it should be able to, provided
you can get the Unicode character sequence for it.

A while back I wrote a script that I needed a delimiter for much as you
need one and settled on the following:

var myVar = "ޱ";

And unless someone every happened to type that particular sequence then
my app is pretty secure :)

Thanks again...
randelld
Jul 23 '05 #8
In article <ZWONd.315378$Xk.22008@pd7tw3no>,
"Randell D." <re******************************@fiprojects.moc > wrote:
2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...


This may help.

Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Saving stats</title>
<base href="http://spaceplace.jpl.nasa.gov/en/_images/">
<script type="text/javascript">

nullCharacter = "\0"
backSpace = "\b"

orUnicode = "\u0000"
oldChar = "\x00"

alert ( "nullCharacter.length = " + nullCharacter.length + " " +
escape(nullCharacter) +
"\n" +
" backSpace = '" + backSpace + "'" + " " +
escape(backSpace) +
"\n" +
" orUnicode.length = " + orUnicode.length + " " +
escape(orUnicode) +
"\n" +
" oldChar.length = " + oldChar.length + " " +
escape(oldChar))

</script>
</head>
<body >
<p> How is that.</>
</body>
</html>
Jul 23 '05 #9
Robert wrote:
In article <ZWONd.315378$Xk.22008@pd7tw3no>,
"Randell D." <re******************************@fiprojects.moc > wrote:

2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...

This may help.

Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Saving stats</title>
<base href="http://spaceplace.jpl.nasa.gov/en/_images/">
<script type="text/javascript">

nullCharacter = "\0"
backSpace = "\b"

orUnicode = "\u0000"
oldChar = "\x00"

alert ( "nullCharacter.length = " + nullCharacter.length + " " +
escape(nullCharacter) +
"\n" +
" backSpace = '" + backSpace + "'" + " " +
escape(backSpace) +
"\n" +
" orUnicode.length = " + orUnicode.length + " " +
escape(orUnicode) +
"\n" +
" oldChar.length = " + oldChar.length + " " +
escape(oldChar))

</script>
</head>
<body >
<p> How is that.</>
</body>
</html>


Interesting... I've saved that for reference... it took me a second, but
I can understand what you've done...

Cheers
Randell D.
Jul 23 '05 #10
Randy Webb wrote:
Randell D. wrote:
Randy Webb wrote:
Randell D. wrote:

<--snip-->

Thus - can you tell me how I can set a variable called fs equal to
ascii character 8? Or even unicode character 8? (It doesn't have to
be 8 - but something not readily available from qwerty keyboard input)


var fs="";

Copy and paste as desired. Unless someone you know spells a name with
a B like that. Then, you could use :

var fs="";

or something similar.

It doesn't have to be "non-printable", it only has to be unique.


Yep - I agree that it only has to be unique and I'm grateful for your
suggested solution (which I will use) however I guess there is no
method available in javascript to do what I want to do... true? (Just
for a curiosity/js-educational point of view).

Never really tried but instincts tells me it should be able to, provided
you can get the Unicode character sequence for it.

A while back I wrote a script that I needed a delimiter for much as you
need one and settled on the following:

var myVar = "ޱ";

And unless someone every happened to type that particular sequence then
my app is pretty secure :)

Randy,

I have another post,with subject line 'Re: Odd problem: Data from hidden
field is not sent to server...' that you might be able to help with (if
you don't mind). Without duplicating the entire post, basically, *the
value* my box receives from the result of a javascript function does not
get sent to the server - yet if I manually complete the same field, the
manually entered data does get sent to the server.

I'm wondering if you had any similar problem as you mentioned you've
done something similar to me at some point in the past...

If you can help please reply to my other post as it might well help
others at some pointin the future.

Cheers
randelld
Jul 23 '05 #11


Randell D. wrote:

2. How do I read/set a string to an unprintable code? For example, how
can I set the variable a to equal the equivalent of ascii code 7 or 8 or
whatever...


There is a method
String.fromCharCode
which takes one ore more numbers as its arguments and creates a string
with as many characters as arguments where the characters are taken from
the numbers interpreted as Unicode code points, thus
var s = String.fromCharCode(65, 66, 67);
makes s have the value 'ABC' or
var s = String.fromCharCode(8364);
the value '€'.

Check <http://www.unicode.org/> for Unicode code charts.

The other way round is
string.charCodeAt(characterIndex)
e.g. with var s = String.fromCharCode(8364); the expression
s.charCodeAt(0) yields the number 8364.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #12
JRS: In article <Fc********************@comcast.com>, dated Mon, 7 Feb
2005 18:01:06, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
Randell D. wrote:

<--snip-->
Thus - can you tell me how I can set a variable called fs equal to ascii
character 8? Or even unicode character 8? (It doesn't have to be 8 - but
something not readily available from qwerty keyboard input)

Why not with String.fromCharCode() ?

S = String.fromCharCode(0x62b) shows me three peas falling into a wok.

-
comp.lang.javascript FAQ - http://jibbering.com/faq


If that's boilerplate, how about adding "& newsgroup weekly"?

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #13
Dr John Stockton wrote:
JRS: In article <Fc********************@comcast.com>, dated Mon, 7 Feb
2005 18:01:06, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :


<--snip-->
comp.lang.javascript FAQ - http://jibbering.com/faq

If that's boilerplate, how about adding "& newsgroup weekly"?


Semi-boilerplate but close enough that I changed it.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #14

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

Similar topics

6
by: nico | last post by:
In my python scripts, I use a lot of accented characters as I work in french. In order to do this, I put the line # -*- coding: UTF-8 -*- at the beginning of the script file. Then, when I need...
6
by: Spamtrap | last post by:
I only work in Perl occasionaly, and have been searching for a solution for a conversion, and everything I found seems much too complex. All I need to do is take a simple text file and copy...
15
by: Craig Wagner | last post by:
I have a situation where I have a series of character codes stored in the database. In some cases they are the ASCII value of the character, in other cases they are the > 127 character code value...
2
by: Gidi | last post by:
Hi, I'm writing a C# win application program, and i need to transfer my hebrew letters from unicode to ascii, now if i use the ascii encoding it writes me ??? instead of the hebrew letter i've...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
14
by: abhi147 | last post by:
Hi , I want to convert an array of bytes like : {79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3} into Unicode character with ISO-8859-1 standard. Can anyone help me .. how should...
7
by: JTree | last post by:
Hi,all I encountered a problem when using unicode() function to fetch a webpage, I don't know why this happenned. My codes and error messages are: Code: #!/usr/bin/python #Filename: test.py...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
7
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.