+ Start a Discussion
Ram Shiva KumarRam Shiva Kumar 

How to display the return value in VF page

Hi ,
 i have uplaoded the java script  file in staticresoure.  iam getting the pop up correctly. but  ih ave written the function in that file which will return multiplication of 2 numbres . Please suggest me how to display the value returned form the java script.

my ststic resource code is,

function popup() { alert("Hello World") }
function myFunction(a, b) {
    return a * b;


 And the vf code is,

<apex:page >

<html>

<head>
<apex:includeScript value="{!$Resource.jsss}"/>

</head>
</html>

<script type="text/javascript" >
popup()

 myFunction(4,5);
 
 
 

</script>

<apex:pageBlock>


</apex:pageBlock>
</apex:page>
   
Any body suggest me aboutthis.


Regards,
Siva.

 
Alexander TsitsuraAlexander Tsitsura
Hello,

You can output result directly on the page, maybe put this value in a span tag. Note that script should execute after DOM completed loaded.
In my example bellow, the script run after span tag added to the page.
If something is not working, try to investigate errors in developer console(For open console in Google Chrome Press Ctrl+Shift+J (Windows / Linux) or Cmd+Opt+J (Mac).
 
<span id="myspan"></span>
<script>
  var result = myFunction(4,5);
  var span = document.getElementById("myspan");
  var resultNode =  document.createTextNode('' + result);

  span.innerHTML = '';
  span.appendChild(resultNode);
</script>
If it helped you, then please select it the best answers it will help outer also.

Thanks,
Alex