473,785 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9063
> 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.javas cript 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.javas cript 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$X k.22008@pd7tw3n o>,
"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.l ength + " " +
escape(nullChar acter) +
"\n" +
" backSpace = '" + backSpace + "'" + " " +
escape(backSpac e) +
"\n" +
" orUnicode.lengt h = " + orUnicode.lengt h + " " +
escape(orUnicod e) +
"\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$X k.22008@pd7tw3n o>,
"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.l ength + " " +
escape(nullChar acter) +
"\n" +
" backSpace = '" + backSpace + "'" + " " +
escape(backSpac e) +
"\n" +
" orUnicode.lengt h = " + orUnicode.lengt h + " " +
escape(orUnicod e) +
"\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

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

Similar topics

6
5495
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 to store accented characters in a string, I used to prefix the literal string with 'u', like this: mystring = u"prénom" But if I understand well, prefixing a unicode string literal with 'u'
6
18333
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 it, however some specific lines are in fact in UTF8 as printed garbagy characters and they need to be converted to Unicode, so that the new text file can be imported into a desktop program and into some Word documents. For the moment I would be...
15
9831
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 that you use in combination with the ALT key to enter special characters into a document (e.g. ALT+0147 and ALT+0148 get you 'smart quotes'). I'm trying to figure out how (or if it's possible) to obtain the Unicode equivalent of the character...
2
3548
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 entered. I know what the Ascii value of each letter, so i understood that i can transfer my string to BYTE and enter the ascii value by myself. if someone has a better idea, i'll be happy to hear about it. how can i know the Unicode value of a...
24
9072
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 charcaters from an ASCII perspective. I get the following error: > SQLiteCur.execute(sql, row)
14
6424
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 I go about doing it ? Thanks
7
2510
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 #Modified: 2006-12-31
232
13349
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 set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
7
4024
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
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10161
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8986
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7506
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.