Call javascript function from select onChange

So, I have a simple HTML select block and javascript alert function. I want the select window to have an onchange event that will trigger the javascript alert function. This is what I have so far:

HTML

<div style="float: left">Type: <select id="selector" onChange="jsfunction()">
  <option value="Pyr">Pyramidally</option>
  <option value="Lin">In-Lines</option>
  <option value="Sym">Symmetrically</option>
  <option value="Nsym">Non-Symmetrically</option>
</select>
</div>

Javascript

function jsfunction(){
    alert("hi");
}

This does not work, and for life I cannot understand why. Most of the other questions of this kind that I have found offer ""around calling a function that I have, or creating the capital onChange'c' that I also have. Any help possible? I would be very grateful.

+4
source share
1 answer
<!DOCTYPE html>
<html>
    <head>
        <script>
            function jsfunction(){
                alert("hi");
            }
        </script>
    </head>
    <body>
        <select id="selector" onchange="jsfunction()">
            <option value="Pyr">Pyramidally</option>
            <option value="Lin">In-Lines</option>
            <option value="Sym">Symmetrically</option>
            <option value="Nsym">Non-Symmetrically</option>
        </select>
    </body>
</html>

It works. You made a mistake in onchange.

+2

Source: https://habr.com/ru/post/1548438/


All Articles