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>
Comments
Post a Comment