Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Need help on replacement



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
Lombi



Joined: 17 Mar 2008
Posts: 1

PostPosted: Mon Mar 17, 2008 7:50 pm    Post subject: Need help on replacement Reply with quote

hey everyone.

I have a bit of a problem - i'm using javascript to automatically generate web-friendly urls from the titles, but i've run into some issues with special characters

This is the code:

Code:
   function setAlias(objvalue){
      document.newpage.newpagealias.value = makesafe(objvalue);
   }

   function makesafe(text){   
       text = text.replace(" / ","_");
       text = text.replace("'","");
       text = text.replace("\"","");
       text = text.replace("/","_");
       text = text.replace("'","_");
       text = text.replace(" - ","_");
       text = text.replace(" ","_");
       text = text.replace("è","c");
       text = text.replace("š","s");
       text = text.replace("ž","z");
       text = text.replace("È","C");
       text = text.replace("Š","S");
       text = text.replace("Ž","Z");
       text = text.replace( "&", "and");
       text = text.replace( "%", "Percent");
       text = alphanumeric(text);
       text = text.replace("____","_");
       text = text.replace("___","_");
       text = text.replace("__","_");
       text = text.toLowerCase();
      return text;
   }

 function alphanumeric(userval)
{
 
   for(var j=0; j<userval.length; j++)
      {
        var eachChar = userval.charAt(j);
        var hh = eachChar.charCodeAt(0);
        if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (eachChar =="_")  || (eachChar =="-"))
        {
            //
        }
        else   
        {      
            userval = userval.replace(eachChar,"_");
        }
      }
      return userval;
}


The two input fields that are connected here are the following two:

Code:
<input type="text" class="text" name="newpagetitle" value="" size="56" maxlength="255" onchange="setAlias(this.value)" />
and
<input type="text" class="text" name="newpagealias" value="" size="16" maxlength="50" />


basically it should convert all čšžČŠŽ into cszcsz but it does this only for the first of them, then turns the rest into _

So my question is basically...

Does anyone know what would need changing here so that this would work in converting all special characters into regular letters

and ... does anyone know if it's also possible to remove the ending underscore (example from "word_" to "word")?

Thanks so much!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap