Forum Moderators: open

Message Too Old, No Replies

Navigation

navigation,unicode hex

         

designer bhutan

2:05 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



hi
i am new to JS, i have a form which sends sms in arabic language. i managed to get the text converted to hex but

i want to submit the value from the JS function after conveting to hex, to the new window that opens. pls. help

here is my code (if u copy this code and run in browser u can understand my q, i just need to pass the hex value generated to a new window from js function)

<HEAD><TITLE>Unicode 2 converter</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<SCRIPT>
var submitcount;
function reset()
{
submitcount=0;
}

function textCounter(field, countfield) {
countfield.value = field.value.length;
}
function textCountDown(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
</SCRIPT>
<SCRIPT language=javascript type=text/javascript>
<!--
function encode(){
if(document.forms[0].ascii.value!= ''){
var vText = document.forms[0].ascii.value;
document.forms[0].hex.value = convertToHex(vText);
document.forms[0].ascii.focus();
document.forms[0].ascii.blur();
document.forms[0].ascii.select();
}
}
function convertToHex(num) {
var hex = '';
for (i=0;i<num.length;i++)
hex += "0" + num.charCodeAt(i).toString(16).toUpperCase();
return hex;

}

</SCRIPT>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY>
<P>&nbsp;</P>
<FORM name=blah action=""><B>Arabic Text</B><BR>
<textarea onkeydown=textCounter(this.form.ascii,this.form.remLen); onkeyup=textCounter(this.form.ascii,this.form.remLen); name="ascii" cols="75"></textarea>
&nbsp; <BR>
<INPUT tabIndex=2 readOnly maxLength=3 size=5
value=0 name=remLen>
<BR><BR><B>Hex Value:</B><BR>
<textarea name="hex" cols="75"></textarea>
&nbsp; <BR>
<input name="reset" type=reset onClick="document.getElementById('unicodeHTML').innerHTML = ''" value=Clear>
&nbsp;&nbsp;&nbsp;
<INPUT name="button" type=button onclick=encode() value=Submit>
</FORM>
</BODY></HTML>

SpaceFrog

2:22 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Ok you mean you just want to pass the returned value in a new window?
does the page exist? do you want a popup?

designer bhutan

3:05 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



ys to a new window, as a querystring will also do.
a popup or a new page say "test.htm"

SpaceFrog

3:31 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



well you could for example do something like:

function convertToHex(num) {
var hex = '';
for (i=0;i<num.length;i++)
hex += "0" + num.charCodeAt(i).toString(16).toUpperCase();
window.location.href="test.htm?"+hex
}

and on the onload on text.htm parse the url to retrieve hex ...

but it could also be done thru popups, imagine your converter page is opened from a mian page in a popup
you could send back hex to main page with

window.opener.document.form.textbox.value=hex ...

designer bhutan

6:33 am on Mar 1, 2005 (gmt 0)

10+ Year Member



Thanks!

designer bhutan

6:33 am on Mar 1, 2005 (gmt 0)

10+ Year Member



Thanks!

designer bhutan

2:38 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



ok all is right but i have one more small problem. when i put a space i get the hex code 020.

i want javascript to add an xtra 0 at start when ever there is a space eg.

0020 (for space) instead of 3 digit 020

designer bhutan

2:38 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



ok all is right but i have one more small problem. when i put a space i get the hex code 020.

i want javascript to add an xtra 0 at start when ever there is a space eg.

0020 (for space) instead of 3 digit 020

designer bhutan

2:39 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



ok all is right but i have one more small problem. when i put a space i get the hex code 020.

i want javascript to add an xtra 0 at start when ever there is a space eg.

0020 (for space) instead of 3 digit 020

designer bhutan

2:39 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



ok all is right but i have one more small problem. when i put a space i get the hex code 020.

i want javascript to add an xtra 0 at start when ever there is a space eg.

0020 (for space) instead of 3 digit 020

designer bhutan

2:39 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



ok all is right but i have one more small problem. when i put a space i get the hex code 020.

i want javascript to add an xtra 0 at start when ever there is a space eg.

0020 (for space) instead of 3 digit 020

designer bhutan

2:39 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



ok all is right but i have one more small problem. when i put a space i get the hex code 020.

i want javascript to add an xtra 0 at start when ever there is a space eg.

0020 (for space) instead of 3 digit 020

SpaceFrog

2:52 pm on Mar 1, 2005 (gmt 0)

10+ Year Member




function formatage (myvar, varlength)
{
myvar=String(myvar);
while (myvar.length < varlength)
{
myvar = "0"+myvar
}
return myvar;
}

alert(formatage(20,4) )

designer bhutan

3:25 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



pls. copy my code at start of this thread and then press any key folowed by space bar and then u will get the code key code plus the code 020, here i want to get 0020 for the no. of space keys pressed.

thanks

SpaceFrog

3:28 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



have u tried:

formatage(hex,4)?

designer bhutan

3:37 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



ys but not getting it, may be i am not putting the code in its proper place.

the hex code for arabic is 4 characters and the code is just fine for all characters but when i put a space in between 2 words its giving me 3 digit code "020" where as i want 4 digit "0020" for space.

i need this cause for sms in arabic language. sorry for troubling u buddy but i am a new bee to programming.

if u copy the complete code and run in browser and type "this is test"

u get the code
074068069073020069073020074065073074

here 020 is for space, instead for space i need to ad xtra 0 at start i.e 0020

SpaceFrog

3:47 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Ok I think I just caught up with you...
you mean if you have a space in the string you convert ...

hex += fomatage("0" + num.charCodeAt(i).toString(16).toUpperCase(),4);

designer bhutan

4:08 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



exactly, i tried with the code u gave me but its givin me the same 3 digit result for space key.

SpaceFrog

4:19 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



hex += fomatage("0" + num.charCodeAt(i).toString(16).toUpperCase(),4);

the 4 is the problem as test is on length and sctricly inferior ...

either you should replace 4 by 5 or change teste to <=

Sorry my mistake!

UH? makes no sens actually?
I have to take a closer look at this ...

SpaceFrog

4:31 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



You must have some misstyping somewhere as this code works fine on my side:

<HEAD><TITLE>Unicode 2 converter</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<style>
.titre1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-size: 18px;
font-weight: bold;
color: #225E7D;
font-style: italic;
}
</style>
<SCRIPT>
var submitcount;
function reset()
{
submitcount=0;
}

function textCounter(field, countfield) {
countfield.value = field.value.length;
}
function textCountDown(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
</SCRIPT>
<SCRIPT language=javascript type=text/javascript>
<!--
//Fonction de formatage
function formatage (myvar, longueur)
{
myvar=String(myvar);
while (myvar.length < longueur)
{
myvar = "0"+myvar
}
return myvar;
}

function encode(){
if(document.forms[0].ascii.value!= ''){
var vText = document.forms[0].ascii.value;
document.forms[0].hex.value = convertToHex(vText);
document.forms[0].ascii.focus();
document.forms[0].ascii.blur();
document.forms[0].ascii.select();
}
}
function convertToHex(num) {
var hex = '';
for (i=0;i<num.length;i++)
hex += formatage("0" + num.charCodeAt(i).toString(16).toUpperCase(),4);
return hex;

}

</SCRIPT>
<META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD>
<BODY>
<P>&nbsp;</P>
<FORM name="blah" action=""><B>Arabic Text</B><BR>
<textarea class="titre1" onkeydown=textCounter(this.form.ascii,this.form.remLen); onkeyup=textCounter(this.form.ascii,this.form.remLen); name="ascii" cols="75" rows="1"></textarea>
&nbsp; <BR>
<INPUT tabIndex=2 readOnly maxLength=3 size=5 value=0 name="remLen">
<BR><BR><B>Hex Value:</B><BR>
<textarea name="hex" cols="75" rows="1"></textarea>
&nbsp; <BR>
<input name="reset" type="reset" value=Clear>
&nbsp;&nbsp;&nbsp;
<INPUT name="button" type=button onclick=encode() value=Submit>
</FORM>
</BODY>

SpaceFrog

4:34 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



and actually does not need "0" + ....

designer bhutan

4:36 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



its working! a million thanks buddy.