Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 76158

Make a Javascript run for every response in a mysql response

$
0
0

I am trying to make a Database application which represents the results of a query in a table. This part works fine but I am trying to implement an external API to populate an additional attribute of the record.

I have written a JavaScript that does that, and it works as intended, it replaces the text with the response of the api.

However, it only works once and all other records are not effected.

How can I make the script run for every record the query returns?

This is the code to generate the table with the Script

 {{#each records}}
    <script lat = {{this.lat}} lon = {{this.lon}}>
    var lat = document.currentScript.getAttribute('lat');
    var lon = document.currentScript.getAttribute('lon');

    what3words.api.convertTo3wa({lat:lat, lng:lon}).then(function(response) {

   document.getElementById('what3words-customer-address').value = response.words;
   document.getElementById('test').innerHTML = response.words;
   });
   </script>
       <tbody>

                        <tr>
                            <td>{{this.name}}</td>
                            <td>{{this.lat}}</td>
                            <td>{{this.lon}}</td>
                            <td id="test">test</td>
                            <td> <button class="btn btn-info" type="button" data-toggle="modal" data-target="#info{{this.id}}">

              <span class="pl-1 d-none d-sm-inline-block">More Info</span>
            </button></td>
                            <td>
                              <button onclick="window.location.href='/shop/edit/{{this.id}}'" class="btn btn-warning" type="button" data-toggle="modal" data-target="#a{{this.id}}">

              <span class="pl-1 d-none d-sm-inline-block">Edit</span>
            </button>

                                <button class="btn btn-danger" type="button" data-toggle="modal" data-target="#a{{this.id}}">

              <span class="pl-1 d-none d-sm-inline-block">Delete</span>
            </button>
                            </td>
                        </tr>

                </tbody>
       ...

{{/each}}

It is supposed to replace all of the the <td> with the id=test but it only does the first one. How can I get it to apply to all of the records? Thanks in advance.


Viewing all articles
Browse latest Browse all 76158

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>