|
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.
[Back to original message]
|