user2629419
user2629419

Reputation: 443

jQuery attach click event on empty select box

using jQuery, how do i load select box options dynamically while clicking on the select box.

I am using redmine REST API's to load issue categories dynamically in to select box.

How do i attach event handler to the selectbox.

But this is not working, i.e event not attaching

<script>
    //dynamically load status values
    $('#newstatusField').on('click',function(){     
        alert('inside');
    });
</script>
<select name="status" id="newstatusField" data-mini="true" data-native-menu="false">
 <!--dynamic option values -->
</select>

Upvotes: 0

Views: 131

Answers (1)

Techno
Techno

Reputation: 44

Always try to wrap the jQuery code inside document.ready fucntion and Change event will work for you :

Edit : Also include latest jQuery library you can download from here jQuery Library

<head>

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>

<script>

    $(document).ready(function()
    {

         $('#newstatusField').on('change',function(){     
            alert('inside');
         });

    });

    </script>

</head>

Upvotes: 2

Related Questions