Display the value of a select list without a button

Posted by Max Zeygelshefer on Stack Overflow See other posts from Stack Overflow or by Max Zeygelshefer
Published on 2013-10-31T21:50:24Z Indexed on 2013/10/31 21:53 UTC
Read the original article Hit count: 139

Filed under:

How can I get the value to be displayed after the selection from the list is made, without the use of a button. I tried to implement an onChange event for the select list, and doing away with the button, but I can't get it to work. I'd like the value (1,2,3) to display below the select box after an option (a,b,c) is selected.

<script>
    function displayResult() {

        this.nextSibling.nodeValue = document.getElementById("mySelect").value;
    }
</script>
<body>
    <form>
        <select id="mySelect" style="width:220px">
            <option value="1">a</option>
            <option value="2">b</option>
            <option value="3">c</option>
        </select>
    </form>
    <button type="button" onclick="displayResult.call(this)">List Locations</button>

© Stack Overflow or respective owner

Related posts about html