Search code examples
javascripthtmlspecial-characters

Insert special characters in textbox


So I have a textbox and I want to add some text( without deleting the one I already have) by clicking a button.. is that possible?

The text I'll be adding will be some html special characters code like é to show a "é"...

or maybe do the reverse, like I write a "é" and then when I submit it changes to é this way it will be easier to the user

Thanks in advance


Solution

  • <input type="text" id="txt" />
    <input type="button" value="Addtext" onclick="addText()" />
    <script>
        function addText() {
            document.getElementById('txt').value += "sometextàéèìòù";
        }
    </script>