13

So I have a simple HTML select box, and a javascript alert function. I want the select box to have an onchange event that will call 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");
}

It doesn't work and for the life of me I can't figure out why. Most other questions of this nature I've found suggest "" around calling the function - which I've got or making the onChange 'c' capital, which I also have. Any possible help? I'd be very grateful.

7
  • it works perfectly on me. JSFIDDLE example Commented Jul 15, 2014 at 5:56
  • I'm using google chrome. I've tried it in IE but it also doesn't work Commented Jul 15, 2014 at 5:57
  • I have, and it works - but I have the exact same code open in another tab and it straight out doesn't work. Bizzare x_X Thankyou?? I don't know whats up Commented Jul 15, 2014 at 5:59
  • 2
    @Genome314 If you're also using JSFiddle, note that one of the default options is "onLoad" compared to the "No wrap" Yaje's fiddle uses. This selection will affect the scope of the code you input. Simple example doesn't work on JSFiddle Commented Jul 15, 2014 at 6:00
  • 1
    @JonathanLonowski That seems to be what the problem was, thank you. Also, thanks Yaje Commented Jul 15, 2014 at 6:03

1 Answer 1

14
<!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.

Sign up to request clarification or add additional context in comments.

1 Comment

nope. onchange is not case-sensitive in html markup

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.