Hi,
I am new to JS but OK in PHP.
I would like to use JS code similar to this' http://www.geocachingtoolbox.com/index.php?page=dancingMen' a php program.
My problem is understanding how this works.
I have posted what seem to be the two key functions and my first attempt to simplify things as well as the link the above link in the hope somebody can get my thinking working in the right direction particularly in understanding the two functions.
Many thanks for a starter for ten,
<script type="text/javascript">
var validChars= new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
var validNums= new Array('0','1','2','3','4','5','6','7','8','9');
function textToIm(){
chars=document.getElementById('dancingMenText').value;
splitChars=chars.split('');
newDiv='';
for(i=0; i<splitChars.length; i++){
lowerChar=splitChars[i].toLowerCase();
if (validChars.indexOf(lowerChar)>-1){
if (i+1==splitChars.length || splitChars[i+1]==' ' || splitChars[i+1]=='\n'){
newDiv+='<img src="pages/dancingMen/'+lowerChar+'v.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">';
}else{
newDiv+='<img src="pages/dancingMen/'+lowerChar+'.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">';
}
}else if (validNums.indexOf(lowerChar)>-1){
newDiv+='<img src="pages/dancingMen/'+lowerChar+'.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">';
}else if (lowerChar!=' '){
newDiv+=splitChars[i];
}
}
newDiv = newDiv.replace(/\n\r?/g, '<br>');
if (chars.length==0){
newDiv='';
}
document.getElementById('dancingMenDiv').innerHTML=newDiv;
}
function imToText(char,space){
if (space==1){
document.getElementById('dancingMenDiv').innerHTML+='<img src="pages/dancingMen/'+char+'v.gif" alt="'+char+'" title="'+char+'">';
document.getElementById('dancingMenText').value+=char+' ';
}else{
document.getElementById('dancingMenDiv').innerHTML+='<img src="pages/dancingMen/'+char+'.gif" alt="'+char+'" title="'+char+'">';
document.getElementById('dancingMenText').value+=char;
}
}
</script>
index.php