You are here: Re: How to convert HTML special characters to the real characters with a Java script « PHP Programming Language « IT news, forums, messages
Re: How to convert HTML special characters to the real characters with a Java script

Posted by Chung Leong on 03/22/06 08:09

Stefan Mueller wrote:
> > function html_entity_decode(s) {
> > var span = document.createElement('SPAN');
> > span.innerHTML = s;
> > return span.innerText;
> > }
>
> Yea, this is exactly what I'm looking for. But like you mentioned it only
> works for IE and not for Mozilla, Opera, Safari, ...
>
> Stefan

Most browsers support innerHTML, even though it's non-standard, because
it's so convinent. innerText is supported only by IE as far as I know.
In the other browsers, you can get the plain text from
span.firstChild.nodeValue.

As I said in the follow-up, it's easier to store the original value in
a hidden field parallel to the input field. Or better yet, use a onload
handler to capture the initial values of every fields. Something like:

function saveOriginalValues() {
var inputs = document.getElementsByTagName('INPUT');
for(var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if(input.type == 'text') {
originalValues[input.name] = input.value;
}
}
}

That gives you something that you can reuse across multiple forms.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация