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> </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>
<BR>
<INPUT tabIndex=2 readOnly maxLength=3 size=5 value=0 name=”remLen”>
<BR>
<input name=”hex” type=”text” value=”” size=”75″>
<BR>
<input name=”reset” type=”reset” value=Clear>
<INPUT name=”button” type=button onclick=encode() value=Submit>
</FORM>
</BODY>