php - How select button in JQuery -


<?php foreach ($list $item): ?>   <tr>     <td>     <div id="<?php echo $item['id']; ?>">     <input type="text" name="name" id="name"/>     <button type="submit" id="ajax_submit" value="<?php echo $item['id']; ?>">run</button>     </div>     </td>   </tr> <?php endforeach; ?> 

in php-code generate html table. when user click on button activate jquery script

 <script>    $(document).ready(function(){      $('button').click(function(){        var id = "#" + $("button").val();           $.post("data/js", { name: $("#name").val(),id : id },            function(data){             $(id).html(data);          });        })     });  </script> 

but, when want select non-first button in table, script run function first. please normal.

ps sorry english ;-(

try this:

<?php foreach ($list $item): ?>   <tr>     <td>     <div id="<?php echo $item['id']; ?>">     <input type="text" name="name" id="name"/>     <button type="submit" id="ajax_submit_<?php echo $item['id']; ?>" value="<?php echo $item['id']; ?>">run</button>     </div>     </td>   </tr> <?php endforeach; ?> 

..

<script>    $(document).ready(function(){      $('button').click(function(){        var id = $(this).attr('value');           $.post("data/js", { name: $(this).prev().attr('name'),id : id },            function(data){             $(id).html(data);          });        })     });  </script> 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -