0

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 page2.php and then they will be returned some results. Fortunately this works well.

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

How can I resolve this problem?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
riztak
  • 55
  • 2
  • 8
  • Make sure you don't have another element on the page with the same id. If two elements on the page have id="select_field" it will cause it not to work. – user2278120 May 04 '16 at 18:00
  • I'm using this jquery code in page1.php:$("#seleccio_test").on("change",function(){ alert("click"); }) – riztak May 04 '16 at 18:00
  • You can't use `there are` and `with id` in the same sentence, that imply that you have more than one elements with the same ID. And plase include the relevant code – Alon Eitan May 04 '16 at 18:04
  • Oh, great then. So if @Rejith's answer is not helpful then please add the code to your question – Alon Eitan May 04 '16 at 18:06
  • We could help a lot more specifically if you showed relevant code and HTML. Abstract questions are hard to write great answers to. Questions with the relevant code are easy to write great answers to. – jfriend00 May 04 '16 at 18:09

1 Answers1

0

Use event delegation for binding events to dynamically added elements.

$(document).on('click', '#select_field', function(){
    //your code
})
rrk
  • 15,677
  • 4
  • 29
  • 45