468,301 Members | 1,521 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

Returning the complete contents of an array to another function

CES
All,

Sorry for the 101 question but I can't figure out how to return all of the
contents of an array to another function. I been able to figure out how to
return individual elements of the array like "return newArray[3]" would
return the value of value4 in the code below but not the complete array.

<html>
<head>
<title></title>

<script language="javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");

return newArray????;
}

function test(){

document.write(tmp())
}
</script>
</head>
<body onload="test()">

</body>
</html>
Any guidance will be appreciated.
CES
Jul 20 '05 #1
2 19211
Lee
CES said:

All,

Sorry for the 101 question but I can't figure out how to return all of the
contents of an array to another function. I been able to figure out how to
return individual elements of the array like "return newArray[3]" would
return the value of value4 in the code below but not the complete array.

<html>
<head>
<title></title>

<script language="javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");

return newArray????;
}

function test(){

document.write(tmp())
}
</script>
</head>
<body onload="test()">

</body>
</html>
Any guidance will be appreciated.


Your argument passing is fine as written.
Don't call document.write() in the body's onload handler.
That makes the page load, and then changes the contents.
It's better to call your function as the body is loading:
<html>
<head>
<title></title>
<script type="text/javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");
return newArray;
}

function test(){
document.write(tmp())
}
</script>
</head>
<body>
<script type="text/javascript">
test();
</script>

</body>
</html>

Jul 20 '05 #2
CES
Lee,
That was 3 hours out of my life...
Thank You.
CES
"Lee" <RE**************@cox.net> wrote in message
news:bl********@drn.newsguy.com...
CES said:

All,

Sorry for the 101 question but I can't figure out how to return all of thecontents of an array to another function. I been able to figure out how toreturn individual elements of the array like "return newArray[3]" would
return the value of value4 in the code below but not the complete array.

<html>
<head>
<title></title>

<script language="javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");

return newArray????;
}

function test(){

document.write(tmp())
}
</script>
</head>
<body onload="test()">

</body>
</html>
Any guidance will be appreciated.


Your argument passing is fine as written.
Don't call document.write() in the body's onload handler.
That makes the page load, and then changes the contents.
It's better to call your function as the body is loading:
<html>
<head>
<title></title>
<script type="text/javascript">
function tmp(){
var newArray = new Array("value1","value2","value3","value4");
return newArray;
}

function test(){
document.write(tmp())
}
</script>
</head>
<body>
<script type="text/javascript">
test();
</script>

</body>
</html>

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

41 posts views Thread by Materialised | last post: by
5 posts views Thread by Cromulent | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.