By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,649 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,649 IT Pros & Developers. It's quick & easy.

Hi, I need some help here!! Please

P: n/a
How to assign Unicode charter (like arabiac) to varibl in javascript

Nov 26 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
sahm wrote:
How to assign Unicode charter (like arabiac) to varibl in javascript
Are you asking about Arabic characters? You can use a text editor that
supports Unicode and save your HTML documents with embedded scripts or
your external script files as UTF-8 then you can use the characters
literally e.g.

var s = "بال*روف العربية";

Or you can use Unicode escape sequences in JavaScript string literals e.g.

var s =
"\u0628\u0627\u0644\u062D\u0631\u0648\u0641\u0020\ u0627\u0644\u0639\u0631\u0628\u064A\u0629";

Finally there is String.fromCharCode e.g.

var s = String.fromCharCode(1576, 1575, 1604, 1581, 1585, 1608, 1601,
32, 1575, 1604, 1593, 1585, 1576, 1610, 1577);

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 26 '06 #2

P: n/a
sahm wrote on 26 nov 2006 in comp.lang.javascript:
How to assign Unicode charter (like arabiac) to varibl in javascript

t = '&#65177' // ? [use alt+grey65177 to type]

<http://srufaculty.sru.edu/david.dailey/javascript/unicode.htm>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 26 '06 #3

P: n/a
Martin Honnen & Evertjan. Thanks for your Reply

In my web page javascript code get the arabiac charter from html text
box and I'm try to use Ajax in my code every time I try to send the
arabiac charter it wont accept it
Please help in this

Nov 26 '06 #4

P: n/a
sahm wrote on 26 nov 2006 in comp.lang.javascript:
Martin Honnen & Evertjan. Thanks for your Reply

In my web page javascript code get the arabiac charter from html text
box and I'm try to use Ajax in my code every time I try to send the
arabiac charter it wont accept it
character?

[please always quote on usenet]

Perhaps show some code?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 26 '06 #5

P: n/a
ASM
sahm a crit :
How to assign Unicode charter (like arabiac) to varibl in javascript
About arabiac I don't know its table-charset

in french :

= \xe9 where e9 is Hexa code for
The best is to write you code in utf-8 directly in arabian in your vars

And, of course, headers sent with html file tells it is in utf-8

--
Stephane Moriaux et son (moins) vieux Mac dj dpass
Stephane Moriaux and his (less) old Mac already out of date
Nov 26 '06 #6

P: n/a
VK

sahm wrote:
In my web page javascript code get the arabiac charter from html text
box and I'm try to use Ajax in my code every time I try to send the
arabiac charter it wont accept it
JavaScript "speaks" Unicode only: respectively it "sees" any page
content as Unicode characters: irrelevant to the encoding used to serve
the page: 8859-6, UTF-8, or something else. I strongly presume that in
your strings handling you are trying to use HTML entities or %-escape
sequences. That is the most common mistake. But as suggested an actual
code sample (or a URL) would greatly help.

Nov 26 '06 #7

P: n/a
sahm wrote:
In my web page javascript code get the arabiac charter from html text
box and I'm try to use Ajax in my code every time I try to send the
arabiac charter it wont accept it
Please show the relevant code and explain in more detail what "it won't
accept it" means. Do you get an error message? If so which one? Is the
character not correctly received on the server? How exactly are you
trying to send it to the server, what server side language/framework do
you use to receive it? There are a lot of settings that matter, for
instance how you encode the characters you send to the server, how the
server decodes them.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 27 '06 #8

P: n/a
Here is the code
This is HTML code
//////////////////////////////
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AJAX with PHP: Quickstart</title>
<script type="text/javascript" src="quickstart.js"
charset="UTF-8"></script>
<head lang="ar">
<meta http-equiv="Content-Language" content="ar-bh">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1256">
</head>
<body onload='process()'>
Server wants to know your name:
<input type="text" id="myName" />
<div id="divMessage" />
</body>
</html>
///////////////////////////////
This is javascript code
///////////////////////////////

var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
var xmlHttp;

if(window.ActiveXObject)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
xmlHttp = false;
}
}

else
{
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
xmlHttp = false;
}
}

if (!xmlHttp)
{
alert("Error creating the XMLHttpRequest object.");
}
else
{
return xmlHttp;
}
}

function process()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
//name =
String.fromCharCode(encodeURIComponent(document.ge tElementById("myName").value));
//alert(name);
name = encodeURIComponent(document.getElementById("myName ").value);
xmlHttp.open("GET", "quickstart.php?name=" + name, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}
else
setTimeout('process()', 1000);
}

function handleServerResponse()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
helloMessage = xmlDocumentElement.firstChild.data;
document.getElementById("divMessage").innerHTML =
'<i>' + helloMessage + '</i>';
setTimeout('process()', 1000);
}
else
{
alert("There was a problem accessing the server: " +
xmlHttp.statusText);
}
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

This is PHP code
///////////////////////////////
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
echo '<response>';
$name = $_GET['name'];
$userNames = array('CRISTIAN', 'BOGDAN', 'شالم', '*سين',
'YODA');
if (in_array(strtoupper($name), $userNames))
echo 'Hello, master ' . htmlentities($name) . '!';
else if (trim($name) == '')
echo 'Stranger, please tell me your name!';
else
echo htmlentities($name) . ', I don\'t know you!';
echo '</response>';
?>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Nov 27 '06 #9

P: n/a
sahm wrote:
This is PHP code
Which PHP version do you have on the server? Have you thought about
sending XML to the server? That way you might have better chances to
correctly submit the Arabic characters as XML supports Unicode and as
PHP's XML parser supports UTF-8.

Your original request sounded as if you wanted to insert Arabic
characters in JavaScript program code but now it looks as if you simply
read out the content of a text input which has Arabic characters. That
should not pose any problems in modern browsers in terms of JavaScript,
the tricky issue is sending stuff to the server and receiving stuff from
the server and getting the encoding/decoding right, in particular with
PHP which treats its strings as sequences of bytes and does not have
support for Unicode unless you use extensions like mbstring.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 27 '06 #10

P: n/a

Martin Honnen wrote:
sahm wrote:
This is PHP code

Which PHP version do you have on the server? Have you thought about
sending XML to the server? That way you might have better chances to
correctly submit the Arabic characters as XML supports Unicode and as
PHP's XML parser supports UTF-8.

Your original request sounded as if you wanted to insert Arabic
characters in JavaScript program code but now it looks as if you simply
read out the content of a text input which has Arabic characters. That
should not pose any problems in modern browsers in terms of JavaScript,
the tricky issue is sending stuff to the server and receiving stuff from
the server and getting the encoding/decoding right, in particular with
PHP which treats its strings as sequences of bytes and does not have
support for Unicode unless you use extensions like mbstring.
--

Martin Honnen
http://JavaScript.FAQTs.com/

More explain please
And how can I send sending XML to php server
I'm new here Please help me

Nov 27 '06 #11

P: n/a
sahm wrote:
More explain please
And how can I send sending XML to php server
You can build an XML DOM document with script and pass that to the send
method of the XMLHttpRequest object.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 28 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.