0

I am printing rows in a talbe as follows. when btnDes cell is clicked, I am able to captuer the variable from the java script.

When the same table is printed via AJAX, same javascript code is not able to capture the event and variables.

Can somebody tell me how to do this?

$counter = 0;
while ($row = $db->getAssocArr($results)) {         
 ?>
<form action="form.php" method="post" id="form-<?php echo $counter; ?>" enctype="multipart/form-data">
<tr>
<td><?php echo $row['name']; ?>
<input type="hidden" value = "<?php echo $row['projId']; ?>" name="projId"/>
</td>
<td><a href="#" name="btnDes">Design</a> | </td>
</tr>
</form>
<?php
        $counter++;
    }

java script

designBtn = document.getElementsByName("btnDes");   
    for (var i = 0; i < designBtn .length; i++) {
        designBtn [i].id = i;           
        designBtn [i].onclick = fdesign;            
    }   
user1000
  • 25
  • 6
  • 1
    since they are dynamically created so you need to do like something:-http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – Alive to die - Anant Feb 06 '16 at 04:59

1 Answers1

0

I had the same issue, I used JQuery to handle it. set a class for that name, try this might helpful

 $(document).ready(function () {
       $('body').on('click', '.btnDes', function (){
          var designBtn  =  $(.btnDes).val();
          for (var i = 0; i < designBtn .length; i++) {
             designBtn [i].id = i;           
             designBtn [i].onclick = fdesign;            
          } 
       }