riztak riztak - 2 years ago 106
Javascript Question

how can I reference a select element?

I have 3 selection fields as following:

  • selection field 1

  • selection field 2

  • selection field 3

The selection field 1 and 2 are filled up through a simple MySql query. What I have to do is when user has selected one or several options from selection field 1 and 2, I need to perform an AJAX request to
and then they will be returned some results. Fortunately this works well.

there is a selection field with id
. The problem appears when I'm trying to reference this id from

How can I resolve this problem?

Answer Source

Use event delegation for binding events to dynamically added elements.

$(document).on('click', '#select_field', function(){
    //your code
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download