Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract variable from a function

Status
Not open for further replies.

davemarsh

Technical User
Feb 11, 2003
12
IN
Code:
function xyz(){
var d=new Date();
}

.. is it possible to extract the non-global 'd' var from that function somewhere else in my code? (the function can't return any value...)
 
davemarsh,

You can make a variable's scope "global" by leaving off var
like:

Code:
<html>
<head>
  <title></title>
<script>
function xyz(){
d = new Date();
}
xyz();
</script>
</head><body>
<script>
document.write(d);
</script>
</body></html>

HTH



Great Javascript Resource:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top