Converting accented characters for form fields as you type

Converting accented characters for form fields as you type

OK, it appears as though some users would like to convert accented characters on at least one field other than the SEF title field, so after an hour of putting together a Polish specific function, a light went off in my head, I can just re-use most of the code within the genSEF function from the default admin.js, and it should cover other accented characters as well... at least as well as the default sNews does.

This javascript function will convert on every keyup event. 95% of this code comes from the sNews default admin.js, I just put the accented character codes and ASCII equivalents into arrays and stuck them in a loop. And I removed the bit which converts spaces to hyphens, now it just collapses excessive whitespace. Obviously it will accept commas as well.

Try it out, type some accented characters below to convert:

To use this to convert your META tags field, or any field for that matter really, simply copy the javascript function below to your admin.js file, just above the closing //]]> bit, or save it as strip_accents.js and call it within your document head;

function strip_accents(str) {
    var out=str.toLowerCase();
    var accented=[
    /[^a-z 0-9,]+/g,
    var stripped=['a','e','i','o','u','b','c','d','f','g','h','j','k','l','m','n','r','p','s','t','v','x','y','z','aa','ae','ch','ce','th','ts','ps','sh','sz','',' '];
    for(var i=0; i<accented.length; i++)
        return out;

Now find the field you want to convert, in this case the "Keywords META Tag (keywords separated by comma):" part, BACK-UP your snews.php file and look for

echo html_input('text', 'keywords_meta', 'km', $frm_meta_key, l('keywords_meta'), '', '', '', '', '', '', '', '', '', '');

then add the strip_accents call

echo html_input('text', 'keywords_meta', 'km', $frm_meta_key, l('keywords_meta'), '', 'onkeyup="this.value=strip_accents(this.value)"', '', '', '', '', '', '', '', '');

That's it, now when you're filling out the meta tags, it should strip any accents. You can do this to any form field, simply by adding the highlighted code onkeyup="this.value=strip_accents(this.value)" to the field.



You might like


No comments have been posted to this page.

Comments are closed. No new comments allowed.

Copyleft 2002 - 2017 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top