javascript - How to get return value on onLoad event -


<html> <head><title>body onload example</title> </head> <body onload="sum(2,3)"> welcome page </body> </html>  function sum(var x,var y){  var z=x+y;  return z;  } 

my problem want store return value of function sum in variable can use later

make global :

var z;  function sum(x,y) { z=x+y; } 

now should available anywhere else in script.


i believe trying do:

script :

var z;  function sum(x,y) {     z = x + y;     document.getelementbyid("mysum").innertext = z; } 

html:

<body onload="sum(2,3)">     welcome page value of      <p>sum : <span id="mysum"></span></p> </body> 

demo


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -