The identifier in HTML must be unique . When the btnAdd button is btnAdd , a duplicate element is generated with the identifiers iuname , buname and finalResult . This causes HTML to become invalid. the problem can be solved with a generic class, then the class selector $('.className') can be used.
Script I added a CSS class here
function GetDynamicTextBox() { return 'Item Code : <select name="iuname" class="iuname required">' + <?php foreach($tItem as $row) : ?> '<option value="<?php echo $row->ProductID;?>"><?php echo $row->ProductID;?></option>' + <?php endforeach;?> '</select>' + ' Batch : <input class="buname" name="buname" >' + '<td class="finalResult"></td>' + '<br/>' }
Event binding
You are currently using direct event binding, event handlers are only bound to the currently selected elements; they must exist on the page when your code is binding to the event.
Since you are dynamically creating elements, Event Delegation must be used with .on () delegated events.
i.e.
$(parentStaticSelector).on('event','selector',callback_function)
Example
$("#TextBoxContainer").on('change', ".iuname", function(){
source share