By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

"Undefined" error when trying to read array from external JavaScript file

P: 58
HI all,

I tried to read an array from an external javascript file called read.js,The array was declared & as well as defined with some values inside the <script> tag of a html file.

For an instance:
test.html:
--------------
<html>
<head>
<script>
var a=new Array(1,2,3);
</script>
<script type="text/javascript" src="read.js"></script>
</head>
</html>

read.js:
----------
a.sort();
alert(a[0]);

test.jsp:
--------------
<html>
<head>
<script>
var a=new Array(1,2,3);
</script>
<script type="text/javascript" src="read.js"></script>
</head>
</html>

This was successful.
But i am getting "undefined " as result when i tried test.html as test.jsp.
I am getting "undefined" message only when i tend to create array
"var a=new Array(1,2,3)" inside the <script>tag of test.jsp,But i did nt get any "undefined" message if i try the same thing with test.html.

I am getting problem while running this code at server side.

can u people guide me in resolving this problem???

Thanks in advance,
sundar
Oct 9 '07 #1
Share this Question
Share on Google+
3 Replies


10K+
P: 13,264
HI all,

I tried to read an array from an external javascript file called read.js,The array was declared & as well as defined with some values inside the <script> tag of a html file.

For an instance:
test.html:
--------------
<html>
<head>
<script>
var a=new Array(1,2,3);
</script>
<script type="text/javascript" src="read.js"></script>
</head>
</html>

read.js:
----------
a.sort();
alert(a[0]);

test.jsp:
--------------
<html>
<head>
<script>
var a=new Array(1,2,3);
</script>
<script type="text/javascript" src="read.js"></script>
</head>
</html>

This was successful.
But i am getting "undefined " as result when i tried test.html as test.jsp.
I am getting "undefined" message only when i tend to create array
"var a=new Array(1,2,3)" inside the <script>tag of test.jsp,But i did nt get any "undefined" message if i try the same thing with test.html.

I am getting problem while running this code at server side.

can u people guide me in resolving this problem???

Thanks in advance,
sundar
Java != Javascript

Moved to Javascript forum
Oct 9 '07 #2

dmjpro
100+
P: 2,476
HI all,

I tried to read an array from an external javascript file called read.js,The array was declared & as well as defined with some values inside the <script> tag of a html file.

For an instance:
test.html:
--------------
<html>
<head>
<script>
var a=new Array(1,2,3);
</script>
<script type="text/javascript" src="read.js"></script>
</head>
</html>

read.js:
----------
a.sort();
alert(a[0]);

test.jsp:
--------------
<html>
<head>
<script>
var a=new Array(1,2,3);
</script>
<script type="text/javascript" src="read.js"></script>
</head>
</html>

This was successful.
But i am getting "undefined " as result when i tried test.html as test.jsp.
I am getting "undefined" message only when i tend to create array
"var a=new Array(1,2,3)" inside the <script>tag of test.jsp,But i did nt get any "undefined" message if i try the same thing with test.html.

I am getting problem while running this code at server side.

can u people guide me in resolving this problem???

Thanks in advance,
sundar
hmmm .....
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var a=new Array(1,2,3);
  3. </script>
  4.  
And use "<%@page contentType = "text/html;charset=utf-8"%>" in ".jsp" at the top.

Debasis Jana
Oct 9 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Changed the thread title to better describe the problem. Please use a good thread title.
Oct 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.