Trigger the event when selected the same value in dropdown?

javascript, jquery

Solution

Simple JS
---------

<html>
<head>
<script>
var prevIndex = "";

function onSelect()
{
    var currIndex = document.getElementById("ddList").selectedIndex;
    if( currIndex > 0 )
    {
        if( prevIndex != currIndex )
        {
            alert("Selected Index = " + currIndex);
            prevIndex = currIndex;
        }
        else
        {
            prevIndex = "";
        }
    }
}
</script>
</head>
<body>
    <select id="ddList" onClick="onSelect()">
        <option value="0">Select Me</option>
        <option value="1">List1</option>
        <option value="2">List2</option>
        <option value="3">List3</option>
    </select>
</body>
</html>

Problem

Issue: I have a dropdown with a list of years in it with nothing selected, the user selects "1976", I run a function. If the user clicks on the dropdown again and selects "1976" AGAIN, I want to run the function again. ``` $('select').on('change', function (e) { var optionSelected = $("option:selected", this); var valueSelected = this.value; alert(valueSelected); }); ```

Original source