Mouhssine tahri

Mouhssine tahri

  • NA
  • 201
  • 9.8k

how use return value function javascript in html

Apr 23 2021 3:36 PM
hello,
 
I want to view sites from my database ,The number of sites varies by company.
 
The display is as follows
 
 
now i want for each site adding information like :total outgoing call in my view is in french Total Appels sortants
for design this page i use the next code :
  1. <fieldset class="fieldset1">  
  2. <div class="row" id="MySite" style=" background-color: mintcream">  
  3. </div>  
  4. </fieldset>  
  5. and function javascript:  
  6. function fillSiteWidget(AllSite) {  
  7. ;  
  8. var wrapperSite = document.getElementById("MySite");  
  9. AllSite.forEach(allsite => {  
  10. var myname = allsite.site;  
  11. myHTML += '<div class="col-md-4">'  
  12. myHTML += '<section class="widget" style="margin-top:20px">'  
  13. myHTML += '<div class="widget-controls">'  
  14. myHTML += '</div>'  
  15. myHTML += '<div class="widget-body" >'  
  16. myHTML += ' <div class="widget-top-overflow windget-padding-md clearfix bg-info text-white" style="-moz-border-radius: 10px;-webkit-border-radius: 10px;border-radius: 10px;">'  
  17. myHTML += ' <h4 class="mt-lg mb-lg" style="color:white">' + 'Site :' + '<span class="mt-lg mb-lg" style="font-size:13px;"> <a href="#" onclick="Info_Site(\'' + myname + '\');"> <strong style="color:white" >' + allsite.libellé + '</strong></a></span> '  
  18. myHTML += ' </h4>'  
  19. myHTML += ' <h4 id="doc_head" style="visibility: hidden;">' + allsite.site;  
  20. myHTML += ' </h4>'  
  21. myHTML += ' </div>'  
  22. myHTML += ' </div>'  
  23. myHTML += ' <footer class="bg-body-light">'  
  24. myHTML += ' <ul class="post-comments mt mb-0">'  
  25. myHTML += ' <li>'  
  26. myHTML += ' <div class="comment-body">'  
  27. myHTML += ' <h6 class="author fw-semi-bold" >Total Appels Entrants: <small> </small></h6>'  
  28. myHTML += ' </div>'  
  29. myHTML += ' <div class="comment-body">'  
  30. myHTML += ' <a class="edit" title="Détail des appels :' + allsite.libellé + '<br/> Du ' + formatDate(document.getElementById("datedebut").value) + ' Au ' + formatDate(document.getElementById("datefin").value) + '<br/> Appels Locaux : <br/> Appels nationaux : <br/> Appels Internationaux : <br/> Appels GSM :<br/> Appels Numéros spéciaux :" + data-toggle="tooltip" data-html="true"<h6 class="author fw-semi-bold" >Total Appels sortants : <small id="AppelSortant">' + SiteStatList(allsite.site) + ' </small></h6> </a>'  
  31. myHTML += ' </div>'  
  32. myHTML += ' <div class="comment-body">'  
  33. myHTML += ' <h6 class="author fw-semi-bold">Coût Total: <small></small></h6>'  
  34. myHTML += ' </div>'  
  35. myHTML += ' </li>'  
  36. myHTML += ' <li>'  
  37. myHTML += ' </li>'  
  38. myHTML += ' </ul>'  
  39. myHTML += '</footer>'  
  40. myHTML += '</section>'  
  41. myHTML += '</div>'  
  42. myHTML += '</div>'  
  43. });  
  44. wrapperSite.innerHTML = myHTML;  
  45. }  
for adding "total outgoing call" to each site in my view i creat the next javascript function :
  1. function SiteStatList(CodeSite) {  
  2. var apiurl = "http://localhost:14405/api/StatAppelSortantApi?G_CodeSite=" + CodeSite ;  
  3. $.ajax({  
  4. url: apiurl,  
  5. type: 'GET',  
  6. dataType: 'json',  
  7. success: function (d) {  
  8. TotalNbreAppellSortantBySite = d;  
  9. document.getElementById("AppelSortant").innerHTML = TotalNbreAppellSortantBySite;  
  10. },  
  11. error: function () {  
  12. alert("Error please try again");  
  13. }  
  14. });  
  15. }  
i call this function in the next line :
  1. myHTML += ' <a class="edit" title="Détail des appels :' + allsite.libellé + '<br/> Du ' + formatDate(document.getElementById("datedebut").value) + ' Au ' + formatDate(document.getElementById("datefin").value) + '<br/> Appels Locaux : <br/> Appels nationaux : <br/> Appels Internationaux : <br/> Appels GSM :<br/> Appels Numéros spéciaux :" + data-toggle="tooltip" data-html="true"<h6 class="author fw-semi-bold" >Total Appels sortants : <small id="AppelSortant">' + SiteStatList(allsite.site) + ' </small></h6> </a>'  
normally the result I have if i call :function SiteStatList(CodeSite) 2 result :700 for site1 and 0 for site 2
 
but the result is not good in my view i have 0 for site 1 and undifined for site2, maybe I didn't call my function well
 
thanks for help

Answers (3)