Ascii to unicode

<script type="text/javascript">

Function ascii2unicode(text)
{
unicode= text
return unicode
}
</script>

=)

i want to convert the text to \u???? characters. (A points)

if thats possible. or replace any characters > 127 to "?"(B points) - (assited)

Having problem with unicode characters submmiting to my active x on a different language setings.
i figured i will need a javascript program that will convert any chinese/ñ special characters (ascii >127) to a ? character or convert it to a unicode text then my active x is good to go..

thanx. need info how
LVL 9
Jerry_PangAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
GwynforWebConnect With a Mentor Commented:
this perhaps?

<script>
function hexVal(char){
  decNum=char.charCodeAt(0)
  if ( decNum>127 ){
    hex=decNum.toString(16).toUpperCase();
   switch (hex.length){
    case 2:hex='\\u'+'00'+hex
      return hex
    case 3:hex='\\u'+'0'+hex
      return hex
    default :
      return '\\u'+hex
   }
 }
 else
  return char
}

function convert(str){
 result=''
 for (i=0;i<str.length;i++)
   result+=hexVal(str.charAt(i))
 return result
}
</script>


<input name="t1" size="50">input string<p>
<input value="convert" type="button" onclick="alert(convert(t1.value))">

0
 
Jerry_PangAuthor Commented:
this is what i need
thanx. just posting it here for my history questions.

function hexVal(char){
  decNum=char.charCodeAt(0)
  if ( decNum>127 ){
    hex=decNum.toString(10).toUpperCase();
   switch (hex.length){
    case 2:hex='&#'+'00'+hex + ';'
      return hex
    case 3:hex='&#'+'0'+hex + ';'
      return hex
    default :
      return '&#'+hex + ';'
   }
 }
 else
  return char
}
0
All Courses

From novice to tech pro — start learning today.