/    Sign up×
Community /Pin to ProfileBookmark

Unicode conversion

hi all
i am new to js and need some help, after turning every stone i am posting my problem for a solutions from fellow developers.

i have the following code for converting to hex(unicode) its working fine but its converting the text upon submit i need it to convert as the user goes on typing. just like the counter field that is there on the page.

i think its better if u copy the follwing code and then see it in browser to understand my problem.

thanks in advance


***************************************************

<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>
<input name=”hex” type=”text” value=”” size=”75″>
&nbsp; <BR>
<input name=”reset” type=”reset” value=Clear>
&nbsp;&nbsp;&nbsp;
<INPUT name=”button” type=button onclick=encode() value=Submit>
</FORM>
</BODY>


**************************************************

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @designer_bhutan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...