I’ve been searching – for a good amount of time – for a way to send unicode message using Clickatell API’s .. i didn’t find any solution, though i found a lot people searching just like me for the same solution.

After a lot of searches, trails and testing .. I’ve found a solution posted by [ tried to find the source but couldn't remember ] that does some unicode conversion functions, from which i could find what i want.

I extracted the peace of code i needed, minified it, and here it is:

function d2h(a){return(a+0).toString(16).toUpperCase()}function str2cp(a){var c=0;var n=0;var d='';var e=false;for(var i=0;i0xFFFF){return false}if(c!=0){if(0xDC00<=b&&b<=0xDFFF){if(e){d+=' '}d+=d2h(0x10000+((c-0xD800)<<10)+(b-0xDC00));c=0;continue;e=true}else{return false}}if(0xD800<=b&&b<=0xDBFF){c=b}else{if(e){d+=''}cp=d2h(b);while(cp.length<4){cp='0'+cp}d+=cp;e=true}}return d}

You can download the file here unicode_cp.js [ Size : 430 Byte ]

Instructions :

1- Include the script into your page containing the form


2- Create a textarea as the message text , it’s better that it doesn’t have a ‘name’ attribute, so it won’t be submitted, it’s contents will be converted to code points and saved in a hidden input which will be actually submitted with the form.



3- Hook the encoding function to keypress event of the textarea#txt

window.onload= function() {
txtBefore= document.getElementById("txt");
txtEncoded= document.getElementById("encoded");
txtBefore.onkeypress= function(e){
// Allow only backspace [ delete ] button when character count is over 70
if (this.value.length>=70) {
if(e.charCode!=0){
return false;
}
}
};
txtBefore.onkeyup= function(e) {
txtEncoded.value= str2cp(txtBefore.value);
};
};

You can also create a checkbox to enable\disable conversion, in case the user wants to send the message in plain English, hence increasing the message limit, to do that add the following as the first line of onkeypress function :

if(uni_check.checked) return false;

and the following as the first line of onkeyup function :

if(uni_check.checked) { txtEncoded.value = txtBefore.value; return; }

you’d need to declare uni_check in your script like that :

 uni_check = document.getElementById('uni_check'); 

And this way you can submit your forms easily, and send all the SMS you want without no hassle, and with front-end conversion.

  1. very cool & good tip, thank you very much for sharing.

    Can I share this post on my JavaScript library?

    Awaiting your response. Thank