Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! I have Select HTML list on page with a ten elements.
Same there is event Changed Jquery:

$(".item select").change(function(){

});
I want, that event works only clicking at option from Select, but now it event works and after click to scrollbar of select list.
Thank you!
Posted

I think the problem is solvable. I found this interesting solution: http://jsfiddle.net/rniemeyer/LBz6d/[^].

You can add, say, size="10" attribute to the select elements and add 11 element, to show a scroll bar and to make sure that just scrolling does not fire the event, only selection change.

However, I tested this simple code (not requiring HTML5) and could see that it works properly. This is HTML:
HTML
<select size="4" id="newSelect">
    <option>A</option>
    <option>B</option>
    <option>C</option>
    <option>D</option>
    <option>E</option>
    <option>F</option>
</select>

JavaScript:
JavaScript
$( document ).ready(function() {
    $( "#newSelect" ).change(function() {
        alert( "Selection changed: " + this.value );
    });
});

You can run it and see: the event fires only if you change the selection (by clicking at the element or using keyboard, but you really need consistent results here), not when you scroll.

—SA
 
Share this answer
 
You can't change how the browser interprets events. The best you can do is write code that works with how the browser works.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900