Editing a text in javascript with the result of a dropdown value

Viewed 24

I made a piece of code from what I could find on the internet to display in a field, the value selected from a dropdown list with this code.

<input type="text" id="text">
          <script type="text/javascript">
            function update() {
                var select = document.getElementById('list-category');
                var option = select.options[select.selectedIndex];

                document.getElementById('text').value = option.text;
            }
            update();
        </script>

This one works very well but the problem is that the text is displayed in an <input>. It's not very aesthetic and above all, you can have fun modifying it. Do you know how I could make the text display simply? Without necessarily putting it in an <input> ? I have try with console.writebut I don't know the args to pass. Thanks for the help.

1 Answers

Instead of using the <input> tag, you can use the <span> tag. You can update its value with innerHtml property.

Related