I generate through PHP an HTML input (id="newItem") and a HTML paragraph (id="newDesc") in the already existing HTML table (id=detailedTable). After trying to fire off a function by using $("#newItem").change(function()...
, I found out that since it was generated dynamically I had to refer to it using the Jquery .on()
. Now this part works.
My issue is on the return of the Ajax call, I try to change the #newDesc
value, but it is not working. I suspect for the same reason that this ID was dynamically generated.
$("#detailedTable").on('change','#newItem',function(){
var value=$(this).val();
value=value.replace(/\,/,'.');
value="value="+value;
$.ajax({
url:'z-getDesc.php',
type:'POST',
dataType:'json',
data:(value),
success:function(values){
values=values['descriptionA'];
$("#newDesc").val(values);
},
fail: function(xhr, textStatus, errorThrown){
alert('Please try again later');
}
});
});
Up to that point everything works fine, the 'values' variable is returned, all is left is :
How can I refer to #newDesc
id?
Thanks
Edit: To clear some things up:
1- The DOM is initially loaded, and users interact with it, bringing in some changes resulting in an array of data.
2- This arrays is loaded up in a table created via JQuery Datatables by an ajax call; in addition to populating the table with the array, I also generate a line for inline editing, line which contains the afore-mentioned #newItem and #newDesc.