Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading