OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Return value from callback function in Javascript [duplicate]

  • Thread starter Thread starter Pavel Matras
  • Start date Start date
P

Pavel Matras

Guest
I am forced to use some Javascript code:

Code:
<!DOCTYPE html>
<html>
   <head>
      <!-- Must set compatibility to IE9 or greater -->
      <meta http-equiv="X-UA-Compatible" content="IE=9" >

      <!-- include the mongoose UserControl.js library -->
      <!-- NOTE: MAKE SURE TO MAKE THE src PATH RELATIVE TO THIS FILE  -->
      <script type="text/javascript" src="../$app/scripts/UserControl.js"></script>
      <script src="https://code.jquery.com/jquery-3.6.4.js"></script>
      <script type="text/javascript">
         TestFce = 
         {
            getProm: function(prom){
               let hodnota = WSForm.getCompValue(prom, function(value){
                  console.log("Value in callback: " + value);
               });
               return hodnota;
            }
         }
      </script>
   </head>
   <body style="font-family:Arial,Helvetica;font-size:12px">
      <button id="promTest" onclick="promTestClick()">Test value</button>
      <script>
        function promTestClick(){
         let val = TestFce.getProm("text1");
         console.log("Value: " + val);
        }
      </script>
</body>
</html>

And I need to return value from callback function in WSForm.getCompValue, to use it in promTestClick function. But according to console.log, it seems, that functions are called in different order then I need: enter image description here

Please how can I correctly pass value into promTestClick function?

<p>I am forced to use some Javascript code:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<!-- Must set compatibility to IE9 or greater -->
<meta http-equiv="X-UA-Compatible" content="IE=9" >

<!-- include the mongoose UserControl.js library -->
<!-- NOTE: MAKE SURE TO MAKE THE src PATH RELATIVE TO THIS FILE -->
<script type="text/javascript" src="../$app/scripts/UserControl.js"></script>
<script src="https://code.jquery.com/jquery-3.6.4.js"></script>
<script type="text/javascript">
TestFce =
{
getProm: function(prom){
let hodnota = WSForm.getCompValue(prom, function(value){
console.log("Value in callback: " + value);
});
return hodnota;
}
}
</script>
</head>
<body style="font-family:Arial,Helvetica;font-size:12px">
<button id="promTest" onclick="promTestClick()">Test value</button>
<script>
function promTestClick(){
let val = TestFce.getProm("text1");
console.log("Value: " + val);
}
</script>
</body>
</html>
</code></pre>
<p>And I need to return value from callback function in <strong>WSForm.getCompValue</strong>, to use it in <strong>promTestClick</strong> function. But according to console.log, it seems, that functions are called in different order then I need:
<a href="https://i.sstatic.net/BHtZE3Rz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BHtZE3Rz.png" alt="enter image description here" /></a></p>
<p>Please how can I correctly pass value into <strong>promTestClick</strong> function?</p>
 

Latest posts

M
Replies
0
Views
1
MusicLovingIndianGirl
M
Q
Replies
0
Views
1
quora question
Q
Top