0

I try to submit as many as I can by reading the data. But it keeps transmitting only the first data. How do I modify it? in this my code

  <?php
    $sql = "SELECT * FROM test";
    $statement = $conn->prepare($sql);
    $statement->execute();
    $result = $statement->fetchAll();
    foreach($result as $row)
     { 
      ?>
    <input type="text" id="trdAmt" name="trdAmt" value="<?=$row["trdAmt"]?>" />
    
    <script>
            function doAction() {     
                    var trdAmt=$("#trdAmt").val();
                        $.ajax({
                        url : '.test.php',
                        data            : {
                            trdAmt      : trdAmt,                        
                        },         
                        dataType : 'json',
                        async: false,               
                        type            : 'POST',
                        dataType        : 'json',
                        success     : function(result) {
                            if(result.success == false) {
                                alert(result.msg);
                                return;
                            } alert(result.data);
                        }   
                    });  
                }
 </script>
            <script type="text/javascript">  
                $(document).ready(function(){                        
                    $("#tmpBtn").trigger('click');
                });
            </script>
    <?php
    }
    ?>

in this html view

enter image description here

and in this consol.log view

enter image description here

How can i modify my code? I think maybe.. using array.. right??

전준휘
  • 57
  • 4
  • All your inputs have the same ID, so how can the JS code tell them apart? Of course it cannot, so it always picks the same one. An ID must be unique, that is the whole point of it! And also your code puts multiple copies of the `doAction()` function into the page...you cannot have many functions with the same name...the browser will ignore all except the last one – ADyson Aug 18 '23 at 08:13

0 Answers0