Skip to content
Advertisement

Finding the selected index by getElementById isn’t returning the right value

The selection of the “building” drop-down should equal zero. It is on the the first option. Function search() is executed when the button beside the drop-down is selected. For some reason the alert is returning “It didn’t work.”

JavaScript

Here is the selection drop-down.

JavaScript

And here is the button.

JavaScript

Advertisement

Answer

Var a is in the wrong place and you don’t need event.preventDefault(); twice.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement