locked
Dropdown List Open Event RRS feed

  • Question

  • User2037455357 posted

    Hello there.

    I want to fire an event when I open a dropdown list,

    is this possible.  I cannot seem to find an example.  ( Using visual studio 2019 )

    Or to have an OnFocus event on a dropdownList

    Regards

    Rob

    Wednesday, May 29, 2019 3:16 PM

All replies

  • User288213138 posted

    Hi masterdineen,
     
    I wrote a demo for your reference about fire an event when open dropdown list.

    In my code, I'm comparing the currently selected value with the previously selected value,record the current value and compare it with the next value after the comparison is completed.

    I have defined 2 variables.

    hasBlur: is to deal with losing focus.

    Count: is to deal with repeated clicks.
     
    The code:

    <script type="text/javascript">
            $(document).ready(function () {
                var s = null;
                var count = 0;
                var hasBlur = false;
                $("#DropDownList1").click(function () {                
                    var s1 = $('#DropDownList1').val();
                    count++;            
                    if (hasBlur) {
                         if ((s == s1) || s==null   ) {
    // here you could write the code you want when open the dropdown console.log("Hello") count = 0; } hasBlur = false; } else { if ((s == s1 && count > 2) || s == null) {
    // here you could write the code you want when open the dropdown console.log("Hello") count = 0; } else { hasBlur = true; } }
    // record the current to compare s = $('#DropDownList1').val(); }); $("#DropDownList1").blur(function () { hasBlur = true; }) }); </script>

    Best Regards,

    Sam

    Thursday, May 30, 2019 9:21 AM
  • User2037455357 posted

    Hello Sam

    Thank you very much,

    i shall put this to test later and will let you know,

    Thank you again,

    Regards

    Rob

    Thursday, May 30, 2019 9:27 AM