Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Show character instead of entity using JavaScript

Hello,

I use server-side code to convert special characters into html entities.

However the entities look very ugly in the form input boxes.

Can I use JavaScript to turn the entities back into characters?

For example: <input type="text" name="t1" value="&copy; 2008" />

should show © instead of &copy;

I use many other entities as well, that is just an example.  Can I convert all entities to characters in all input boxes using only JavaScript?
Avatar of ysfx
ysfx
Flag of United States of America image

Escape the & in &copy; so that it appears as
&amp;copy;
Avatar of sh0e
sh0e


<script>
var el = document.getElementById('t1');
el.value = el.value.replace(/[&]copy[;]/,'©');
</script>
<input type="text" name="t1" value="&copy; 2008" />

Open in new window

Avatar of hankknight

ASKER

sh0e, your idea is good but not enough.  

I use there are countless entities, not just 1.

Could your idea some how be incorporated with this link?

http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_html_entity_decode/
ASKER CERTIFIED SOLUTION
Avatar of sh0e
sh0e

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial