writing information to a div

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DutchKingCobra
    New Member
    • Mar 2007
    • 37

    #16
    hi pal
    im back again,
    and i think im on to something!

    check this. :)

    Code:
    <html>
    <!-- Created on: 14-4-2007 -->
    <head>
      <title></title>
    <script language="JavaScript1.2">  
    //array of non allowed characters
    NotAllowed = new Array();
    NotAllowed[0]='@';
    NotAllowed[1]='!';
    NotAllowed[2]='"';
    NotAllowed[3]='$';
    NotAllowed[4]='%';
    NotAllowed[5]='&';
    NotAllowed[6]='_';
    NotAllowed[7]='(';
    NotAllowed[8]=')';
    NotAllowed[9]='\'';
    NotAllowed[10]='?';
    NotAllowed[11]='/';
    NotAllowed[12]='\\';
    NotAllowed[13]='~';
    NotAllowed[14]='°';
    NotAllowed[15]='¸';
    NotAllowed[16]='}';
    NotAllowed[17]='{';
    NotAllowed[18]='£';
    NotAllowed[19]='¾';
    NotAllowed[20]='½';
    NotAllowed[21]='¼';
    NotAllowed[22]='¬';
    NotAllowed[23]='§';
    NotAllowed[24]='|';
    NotAllowed[25]='¨';
    NotAllowed[26]='*';
    NotAllowed[27]='<';
    NotAllowed[28]='>';
    NotAllowed[29]='`';
    NotAllowed[30]='´';
    NotAllowed[31]='±';
    NotAllowed[32]='=';
    NotAllowed[33]='-';
    NotAllowed[34]='.';
    NotAllowed[35]=';';
    NotAllowed[36]=':';
    NotAllowed[37]=',';
    NotAllowed[38]='.';
    NotAllowed[39]='»';
    NotAllowed[40]='µ';
    NotAllowed[41]='¦';
    NotAllowed[42]='[';
    NotAllowed[43]=']';
    NotAllowed[44]='#';
    NotAllowed[45]=' ';		
    
    var i = 0;
    function displaynames(){
    heading=document.getElementById('mydiv');//the display div
    names='111###22"2###3#33###44"4###55$5###6%66###7&77###8_88###9(99###101 010';//the string
    		   
    nextname = names.split("###");//split names
    
    for (XxX=0;XxX<NotAllowed.length;++XxX){
    teststring=nextname[i].indexOf(NotAllowed[XxX])+1;//compare string for illegal charaters by looping through array 
    if(teststring!='0'){//if an illegal charater has been found 
    firstpart=nextname[i].substring(0,teststring-1);//get the first piece of string before illegal character
    secondpart=nextname[i].substring(teststring,nextname[i].length);//get the last piece of the string behind the illegal character
    nextname[i]=firstpart+secondpart;//rejoin them
    } 
    else{
    
    }
    }
    
    if (nextname[i]==null){
    heading.innerHTML = 'finished';
    return false;
    }else{
    heading.innerHTML = nextname[i];
    i++;
    setTimeout('displaynames()',2000);
    }
    }
    
     </script> 
    </head>
    <body onload="displaynames()">
    
    <div id="mydiv"></div>
    </body>
    </html>
    well let me know what u think
    peace

    Comment

    • gomzi
      Contributor
      • Mar 2007
      • 304

      #17
      Originally posted by DutchKingCobra
      hi pal
      im back again,
      and i think im on to something!

      check this. :)

      Code:
      <html>
      <!-- Created on: 14-4-2007 -->
      <head>
        <title></title>
      <script language="JavaScript1.2">  
      //array of non allowed characters
      NotAllowed = new Array();
      NotAllowed[0]='@';
      NotAllowed[1]='!';
      NotAllowed[2]='"';
      NotAllowed[3]='$';
      NotAllowed[4]='%';
      NotAllowed[5]='&';
      NotAllowed[6]='_';
      NotAllowed[7]='(';
      NotAllowed[8]=')';
      NotAllowed[9]='\'';
      NotAllowed[10]='?';
      NotAllowed[11]='/';
      NotAllowed[12]='\\';
      NotAllowed[13]='~';
      NotAllowed[14]='°';
      NotAllowed[15]='¸';
      NotAllowed[16]='}';
      NotAllowed[17]='{';
      NotAllowed[18]='£';
      NotAllowed[19]='¾';
      NotAllowed[20]='½';
      NotAllowed[21]='¼';
      NotAllowed[22]='¬';
      NotAllowed[23]='§';
      NotAllowed[24]='|';
      NotAllowed[25]='¨';
      NotAllowed[26]='*';
      NotAllowed[27]='<';
      NotAllowed[28]='>';
      NotAllowed[29]='`';
      NotAllowed[30]='´';
      NotAllowed[31]='±';
      NotAllowed[32]='=';
      NotAllowed[33]='-';
      NotAllowed[34]='.';
      NotAllowed[35]=';';
      NotAllowed[36]=':';
      NotAllowed[37]=',';
      NotAllowed[38]='.';
      NotAllowed[39]='»';
      NotAllowed[40]='µ';
      NotAllowed[41]='¦';
      NotAllowed[42]='[';
      NotAllowed[43]=']';
      NotAllowed[44]='#';
      NotAllowed[45]=' ';		
      
      var i = 0;
      function displaynames(){
      heading=document.getElementById('mydiv');//the display div
      names='111###22"2###3#33###44"4###55$5###6%66###7&77###8_88###9(99###101 010';//the string
      		   
      nextname = names.split("###");//split names
      
      for (XxX=0;XxX<NotAllowed.length;++XxX){
      teststring=nextname[i].indexOf(NotAllowed[XxX])+1;//compare string for illegal charaters by looping through array 
      if(teststring!='0'){//if an illegal charater has been found 
      firstpart=nextname[i].substring(0,teststring-1);//get the first piece of string before illegal character
      secondpart=nextname[i].substring(teststring,nextname[i].length);//get the last piece of the string behind the illegal character
      nextname[i]=firstpart+secondpart;//rejoin them
      } 
      else{
      
      }
      }
      
      if (nextname[i]==null){
      heading.innerHTML = 'finished';
      return false;
      }else{
      heading.innerHTML = nextname[i];
      i++;
      setTimeout('displaynames()',2000);
      }
      }
      
       </script> 
      </head>
      <body onload="displaynames()">
      
      <div id="mydiv"></div>
      </body>
      </html>
      well let me know what u think
      peace

      Thanks a lot man for taking the pains in trying to solve my problem...
      nice idea of declaring the illegal characters in the beginning ... but thought that the same could have been done easily using the replace function...
      also.... in case the string is something like this -> tom'jer"ry
      then that code wont work because it will remove ' and combine to give,
      tomjer"ry, which can be overcome using the replace function.

      anyway... my problem is that i am passing values to the displaynames function and not declaring my string inside, so when the string am passing to the function contains an illegal character it throws an error.doesnt go into the function also in that case.

      Comment

      Working...