Selectionproblem in $(document).on("click"...

Selectionproblem in $(document).on("click"...

Hi

As I am still a beginner I would like to ask you how I can solve my issue here.
I have a multiple forms divided via an "objectid" which contain one input text field (for a lastname) and a hidden field (which should contain the contactid from the response later on)
As I call an ajax script  via onkeyup   via jquery, the ajax returns a list of contakts with a button (to taken over that contact into the form by a click) at the end for each listed contact.

Now I want to use jquery to move the contactid from the response to the hidden field to the apropriate form (identifier is the objectid which will be passed through the complete workflow) and that is difficult as the selector on the button (in the ajax result) cannot be selected via normal jquery as that content will be loaded after DOM is ready.

So therefore I have tried to use the

$(document).on("click" function 

which is working well and I can pick up the relevant information from my ajax response (So an alert(objectid + "/" + contactid); is working fine).

But now I want to place that response id into the hidden field. But I can't select that field via jquery selector as usual.

Who can help?


My scripts in the main page:

The ajax call:

  1. $("input[name='lastname']").keyup(function(){
  2. var id = $(this).attr("ref");
  3. var lastname = $("#lastname_" + id).attr("value");
  4.         $.ajax({
  5.       url: "/admin/vakanzsuche/ajax_getUser.php",
  6.       type: "POST",
  7.       data: 'lastname=' + lastname + "&objektid=" + id,
  8.       success: function (response) {
  9.             $("#result_" + id).html(response);
  10.       } // END success: function (response) {
  11. }); // END $.ajax({

  12. }); // END $("input[name='lastname']").keyup(function(){

To 'bind' the trigger into the result of the ajax response
  1. $(document).on("click",".takeContact",function(e){
  2.       var id = this.id;
  3.       var pos = id.indexOf(":");
  4.       var contactid = id.substring(0,pos);
  5.       var objectid = id.substring(pos,id.length);
  6.       alert(contactid + " : " + objectid); //THAT WORKS GREAT!
  7.       $("contact_id_" + objectid).attr("value",contactid); // THAT DOESNT WORK! :(
  8. });

The ajax script delivers: The objectid and the contactid (from a database). Also that works fine.
  1. echo '<button type="button" id="'.$array['id'].":".$objektid.'" class="takeContact">Take Over</button>';

Hope you understand.

Thanks!